The following example demonstrates a C main module calling a Pascal procedure, maxparam. This procedure adjusts the lower of two arguments to be equal to the higher argument.
/* C source file - calls Pascal procedure.
* Compile in medium or large model.
*/
void __pascal maxparam( int __near * a, int __near * b );
/* Declare as void, because there is no return value.
* The __pascal keyword causes C to use FORTRAN/Pascal
* calling and naming conventions.
* Two integer params, passed by near reference.
*/
main()
{
int a = 5;
int b = 7;
printf( “a = %d, b = %d”, a, b );
maxparam( &a, &b );
printf( “a = %d, b = %d”, a, b );
}
{ Pascal source code - Maxparam procedure. }
MODULE Psub;
PROCEDURE Maxparam( VAR a:INTEGER; VAR b:INTEGER );
{ Two integer parameters are received by near reference. }
{ Near reference is specified with the VAR keyword. }
BEGIN
if a > b THEN
b := a
ELSE
a := b
END;
END.
In the example above, the C program adopts the Pascal naming convention and calling convention. Both programs must agree on whether parameters are passed by reference or by value; the following keywords affect the conventions:
The __pascal keyword directs C to call Maxparam with the FORTRAN/Pascal naming convention (as MAXPARAM); __pascal also directs C to call Maxparam with the FORTRAN/Pascal calling convention.
Since the procedure Maxparam can alter the value of either parameter, both parameters must be passed by reference. In this case, near reference is used; this method is specified in C by the use of near pointers, and in Pascal with the VAR keyword.
Far reference could have been specified by using far pointers in C. To specify far reference in Pascal, use the VARS keyword instead of VAR.