Fortran Programming Guide

COMPLEX Data

Pass a Fortran COMPLEX data item as a pointer to a C struct of two float or two double data types:

Table 11-5 Passing COMPLEX Data Types

Fortran calls C 

C calls Fortran 

complex w

double complex z

external CCmplx

call CCmplx(w,z)

...

------------------------------

struct cpx {float r, i;};

struct dpx {double r,i;};

void ccmplx_(

struct cpx *w,

struct dpx *z)

{

w -> r = 32.;

w -> i = .007;

z -> r = 66.67;

z -> i = 94.1;

}

struct cpx {float r, i;};

struct cpx d1;

struct cpx *w = &d1;

struct dpx {double r, i;};

struct dpx d2;

struct dpx *z = &d2;

fcmplx_( w, z );

...

---------------

subroutine FCmplx( w, z )

complex w

double complex z

w = (32., .007)

z = (66.67, 94.1)

return

end

In 64-bit environments and compiling with -xarch=v9, COMPLEX values are returned in registers.