HP C Programmer's Guide (92434-90009)

Chapter 5 157
Programming for Portability
Calling Other Languages
It should be noted that a FORTRAN main should not be linked with cc.
Calling Pascal
Pascal gives you the choice of passing parameters by value or by reference (var
parameters). C passes all parameters (other than arrays and structures) by value, but
allows passing pointers to simulate pass by reference. If the Pascal function does not use
var parameters, then you may pass values just as you would to a C function. Actual
parameters in the call from the C program corresponding to formal var parameters in the
definition of the Pascal function should be pointers.
Arrays correlate fairly well between C and Pascal because elements of a multidimensional
array are stored in row-major order in both languages. That is, elements are stored by
rows; the rightmost subscript varies fastest as elements are accessed in storage order.
Note that C has no special type for boolean or logical expressions. Instead, any integer can
be used with a zero value representing false, and non-zero representing true. Also, C
performs all integer math in full precision (32-bit); the result is then truncated to the
appropriate destination size.
To call Pascal procedures from C on the Series 700/800, a program may first have to call
the Pascal procedure U_INIT_TRAPS. See the HP Pascal Programmer's Guide for details
about the TRY/RECOVER mechanism.
As true of FORTRAN mains, a Pascal main should not be linked with cc.
The following source is the Pascal module:
module a;
export
function cfunc : integer;
function dfunc : integer;
implement
function cfunc : integer;
var x : integer;
begin
x := MAXINT;
cfunc := x;
end;
function dfunc : integer;
var x : integer;
begin
x := MININT;
dfunc := x;
end;
end.
The command line for producing the Pascal relocatable object is
$ pc -c pfunc.p