Interoperability of types

Intrinsic types

XL Fortran provides the ISO_C_BINDING intrinsic module that contains named constants holding kind type parameter values for intrinsic types. Their names are shown together with the corresponding C types in Table 32. Only those intrinsic types listed in the table are interoperable; other intrinsic types are not.

Derived types

XL Fortran provides the ability to define derived types that correspond to C struct types. A Fortran derived type is interoperable with a C struct type if all of the following conditions are met:

For example, the C type myctype, declared below, is interoperable with the Fortran type myftype, declared below.

typedef struct {
  int m, n;
  float r;
} myctype;
USE, INTRINSIC :: ISO_C_BINDING
TYPE, BIND(C) :: MYFTYPE
  INTEGER(C_INT) :: I, J
  REAL(C_FLOAT) :: S
END TYPE MYFTYPE

Note that the names of the corresponding components of the derived type and the C struct type need not be the same; the names are not significant in determining whether the Fortran derived type and C struct type are interoperable.

There is no Fortran type that is interoperable with a C struct type that contains a bit field or that contains a flexible array member. There is no Fortran type that is interoperable with a C union type.

Notes:
  1. A derived type with the BIND attribute cannot be a SEQUENCE type.
  2. A component of a derived type with the BIND attribute must have interoperable type and type parameters, and cannot have the POINTER or ALLOCATABLE attribute.