HP Pascal/iX Programmer's Guide (31502-90023)

9- 18
You must write a switch stub for each Compatibility Mode routine that
your program calls. The Switch Assist Tool (SWAT), an interactive
utility, can help you write your switch stubs (see step 2 of the example
in "Calling SPL from HP Pascal" ). For more information, refer to the
Switch Programming Guide
.
How Non-Pascal Programs Call Pascal Routines
A program written in C, COBOL II, FORTRAN 66/V, FORTRAN 77, or SPL can
call an external routine written in HP Pascal. You must match the formal
parameters and result type of the HP Pascal routine with those that the
calling program specifies.
The matching rules are:
* Corresponding formal parameter lists must have the same number of
parameters in the same order. If the Pascal routine requires
hidden parameters, the non-Pascal routine must have actual
parameters that correspond to them (see Chapter 7 for
details).
* Corresponding formal parameters must be of corresponding types.
Correspondence depends upon the source language of the external
routine. See the parameter descriptions in "EXTERNAL Directive"
.
* Corresponding formal parameters can have different names.
Example 1
This C program calls the external Pascal procedure pas:
main()
{ extern void pas(); /*This is non ANSI C */
char carr[21];
short sint1, sint2;
short sum;
strcpy(carr, "Add these 2 numbers ");
sint1 = 25;
sint2 = 15;
pas(carr, sint1, sint2, &sum);
}
This Pascal program contains the procedure pas:
$SUBPROGRAM$
PROGRAM Pas_Proc;
TYPE
arr = PACKED ARRAY [1..21] OF char;
PROCEDURE pas (VAR carr : arr;
sint1 : shortint;
sint2 : shortint;
VAR sum : shortint);
BEGIN
carr := 'Sum of two numbers: '#0;
sum := sint1 + sint2;
END;
BEGIN
END.
Example 2
The COBOL II program COBOL-TO-PASCAL calls the external Pascal procedure
pasprog.