Export (0) Print
Expand All

Structures, COMPLEX, and LOGICAL Types

Visual Studio 6.0

The Fortran structure variable, defined with the STRUCTURE keyword and declared with the RECORD statement, is equivalent to C struct declarations. You can pass structures by value or by reference. Be careful, however, about the effect of structure alignment if you are going to share structures.

C, C++, and MASM do not directly implement the Fortran types COMPLEX*8 and COMPLEX*16. However, you can write structures that are equivalent. The type COMPLEX*8 has two fields, both of which are 4-byte floating-point numbers; the first contains the real-number component, and the second contains the imaginary-number component. The type COMPLEX is equivalent to the type COMPLEX*8. The type COMPLEX*16 is similar to COMPLEX*8. The only difference is that each field of COMPLEX*16 contains an 8-byte floating-point number.

Note   Fortran functions of type COMPLEX place a hidden COMPLEX argument at the beginning of the parameter list. C functions that implement such a call from Fortran must declare this argument explicitly, and use it to return a value. The C return type should be void.

Here are the C/C++ structure definitions for the Fortran COMPLEX types.

struct complex8 {
    float   real, imag;
};

struct complex16 {
    double  real, imag;
};

A Fortran LOGICAL*2 is stored as a 1-byte indicator value (1=true, 0=false) followed by one unused byte. A Fortran LOGICAL*4 is stored as a 1-byte indicator value followed by three unused bytes. The type LOGICAL is equivalent to LOGICAL*4.

To pass or receive a Fortran LOGICAL type, use an integer. Note that only the low byte is tested or used by Fortran.

The C++ class type has the same layout as the corresponding C struct type, unless the class defines virtual functions or has base classes. Classes that lack those features can be passed in the same way as C structures.

Show:
© 2014 Microsoft