Handling User-Defined Types

Fortran 95/90 supports user-defined types (data structures similar to C structures). User-defined types can be passed in modules and common blocks just as other data types, but the other language must know the type's structure.

For example:

Fortran Code:

     TYPE LOTTA_DATA         SEQUENCE         REAL A         INTEGER B         CHARACTER(30) INFO         COMPLEX CX         CHARACTER(80) MOREINFO      END TYPE LOTTA_DATA      TYPE (LOTTA_DATA) D1, D2      COMMON /T_BLOCK/ D1, D2

In the Fortran code above, the SEQUENCE statement preserves the storage order of the derived-type definition.

C Code:

 /* C code accessing D1 and D2 */ extern struct {    struct {       float a;       int b;       char info[30];       struct {          float real, imag;          } cx;       char moreinfo[80];    } d1, d2; } t_block;