HP C Programmer's Guide (92434-90009)

50 Chapter3
Calling Other Languages
Comparing HP C and HP Pascal
unsigned int b9 : 1;
} SET_10;
SET_10 s;
Also, the following operation in HP Pascal:
s := s + [9];
has the following corresponding HP C code:
s.b9 = 1;
15.HP C and HP Pascal file types and I/O operations do not correspond.
Passing Parameters Between HP C and HP Pascal
This section describes additional information on parameter passing.
1. All HP C parameters are passed by value except arrays and functions, which are always
passed as pointers. Reference parameters to HP Pascal can be implemented in two
ways: first, by passing the address of an object by applying the address operator & to the
variable; second, by declaring a variable to be a pointer to such a type, assigning an
address to the pointer variable, and passing the pointer.
If an HP Pascal procedure or function has a parameter that is an array by value, it can
be called from HP C by passing a struct that contains an array of the corresponding
type.
2. Be careful when passing strings to HP Pascal. If the routine expects a packed array of
char, be sure to pass a char array. If the routine expects a user-defined string, pass the
structure declared in Note 5 above.
The examples below are HP Pascal and HP C source files that show the parameter
passing rules. The HP Pascal file contains 2 subroutines, pass_char_arrays() and
pass_a_string(). The HP C file contains the main line routine that calls these two
subroutines and displays the results. The HP C program is annotated with the expected
results.
The following is the HP Pascal procedure called from HP C:
$subprogram$
program p;
const len = 10;
type
pac_10 = packed array [1..10] of char;
string_10 = string [len];
function pass_char_arrays (a: pac_10;
var b: pac_10;
c: string_10;
var d: string_10) : integer;
var
i : integer;
ret_val : integer;
begin