HP C Programmer's Guide (92434-90009)
154 Chapter5
Programming for Portability
Calling Other Languages
Calling Other Languages
It is possible to call a routine written in another language from a C program, but you
should have a good reason for doing so. Using more than one language in a program that
you plan to port to another system will complicate the process. In any case, make sure that
the program is thoroughly tested in any new environment.
If you do call another language from C, you will have the other language's anomalies to
consider plus possible differences in parameter passing. Since all HP-UX system routines
are C programs, calling programs written in other languages should be an uncommon
event. If you choose to do so, remember that C passes all parameters by value except
arrays and structures. The ramiļ¬cations of this depend on the language of the called
function.
Table 5-5. C Interfacing Compatibility
C HP-UX Pascal FORTRAN
char none byte
unsigned char char character (couldresideonanodd
boundary and cause a memory
fault)
char * (string) none none
unsigned char *
(string)
PAC+chr(0) (PAC = packed
array[1..
n
] of char)
Array of char+char(0)
short (int) -32768..32767(shortint onSeries
700/800)
integer*2
unsigned short (int) BIT16 on Series 700/800; none on
Series 300/400 (0..65535 will
generate a 16-bit value only if in a
packed structure)
none
int integer integer (*4)
long (int) integer integer (*4)
unsigned (int) none none
float real real (*4)
double longreal real*8
long double
a
none real*16
type* (pointer) ^var, pass by reference, or use
anyvar
none
&var (address) addr(var) (requires $SYSPROG$) none
*var (deref) var^ none