HP MLIB User's Guide Vol. 2 7th Ed.

Appendix A 1087
General interlanguage programming rules
Because C does not support complex arithmetic in a predefined way, storage
layouts for Fortran types COMPLEX*8 and COMPLEX*16 usually are defined
by typedef statements. Use the following typedef statements:
typedef struct {float re, im;} complex8_t;
/* COMPLEX*8 type */
typedef struct {double re, im;} complex16_t;
/* COMPLEX*16 type */
Using the above typedef statements, Fortran and C declarations are
related as shown in the table below.
Relationship Between Fortran and C Declarations
There is the possibility of an incompatibility between Fortran COMPLEX*8
data storage and the complex8_t typedef defined above. The PA Fortran
compiler assumes COMPLEX*8 data is 8-byte aligned. Therefore, the compiler
may use an 8-byte load instruction to simultaneously load both the real and
imaginary component. Much of the source in the MLIB library is written in
Fortran and the Fortran compiler may use these 8-byte loads.
Using the complex8_t structure in C implies the individual components are
4-byte aligned, but does not imply the complex8_t structure is 8-byte aligned.
Therefore, if a C routine uses the above typedef and calls MLIB routines that
manipulate COMPLEX*8 data, an illegal operation may occur.
Fortran C
LOGICAL*4 l int l;
INTEGER*4 i int i;
INTEGER*8 i long long int i;
REAL*4 s float s;
REAL*8 d double d;
COMPLEX*8 c complex8_t c;
COMPLEX*16 z complex16_t z;
CHARACTER*(n) t char t[n];
PROGRAM main main ()
SUBROUTINE sub (...) void sub (...)
SUBROUTINE SUB (...) void sub (...)
INTEGER*4 FUNCTION intf(...) int intf (...)
REAL*4 FUNCTION sf (...) float sf(...)
REAL*8 FUNCTION df (...) double df (...)
COMPLEX*8 FUNCTION cf (...) complex8_t cf (...)
COMPLEX*16 FUNCTION zf (...) complex16_t zf(...)