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

9- 6
real Re ;
unsigned char Ch ;
} UnionType ;
corresponds to the
untagged
HP Pascal record variant
UnionType = RECORD CASE integer OF
1 : (In : integer) ;
2 : (Re : real) ;
3 : (Ch : char) ;
END ;
while the
tagged
HP Pascal record variant
Tagged_UnionType = RECORD CASE Tag : integer OF
1 : (In : integer) ;
2 : (Re : real) ;
END ;
corresponds to the C
struct
type
typedef struct
{
Tag : int ;
union
{
int : In ;
float : Re ;
}
} Tagged_UnionType ;
5. The value of an HP C variable of type
(char *)
ends with a NULL.
The HP Pascal type
string[n]
, where
n
is the maximum length,
corresponds to the HP C type
(char *)
, but has a different layout.
HP Pascal treats string parameters to external C routines
differently. Just before the call to the C routine, HP Pascal
puts a NULL character after the current length of the HP Pascal
string parameter. The address sent to the C routine is that of
the data part of the HP Pascal string parameter. When the C
routine returns to the HP Pascal program, HP Pascal strips the
NULL character from the HP Pascal string and updates its current
length.
6. To pass an actual parameter of this type to a C routine, declare
the formal parameter in the EXTERNAL declaration to be of type
integer
(in the Pascal compilation unit that makes the call).
Before calling the C routine, call the predefined function
waddress
to get the integer address of the Pascal routine. Pass
the integer address to the C routine. For example:
A C function:
int Signal (Sig , Func)
int Sig ;
int (*Func) () ; /* functional parameter */
{
...
}
A portion of the HP Pascal program that calls the C function:
{ EXTERNAL declaration for C function Signal }
FUNCTION Signal (Sig : integer ; Func : integer) ;
EXTERNAL C ;
{ Procedure whose address is passed to C function Signal }
PROCEDURE Signal_Handler (Sig : integer) ;