Structures, Records, and User-Defined Types

The C struct type, the BASIC user-defined type, the FORTRAN record (defined with the STRUCTURE keyword), and the Pascal record type are equivalent. Therefore, these data types can be passed between C, FORTRAN, Pascal, and BASIC.

These types can be affected by the storage method. By default, C, FORTRAN, and Pascal use word alignment for types shorter than one word (type char and unsigned char). This storage method specifies that occasional bytes can be inserted as padding so that word and double-word objects start on an even boundary. (In addition, all nested structures and records start on a word boundary.)

If you are passing a structure or record across a mixed-language interface, your calling routine and called routine must agree on the storage method and parameter-passing convention. Otherwise, data will not be interpreted correctly.

Because Pascal, FORTRAN, and C use the same storage method for structures and records, you can interchange data between routines without taking any special precautions unless you modify the storage method. Make sure the storage methods agree before interchanging data between C, FORTRAN, and Pascal.

BASIC packs user-defined types, so your C function must also pack structures (using the /Zp command-line option or the pack pragma) to agree.

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.

You can pass structures as parameters by value or by reference. Both the calling program and the called program must agree on the parameter-passing convention. See “Parameter-Passing Requirement” for more information about the language you are using.