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 27. Only those intrinsic types listed in the table are interoperable; other intrinsic types are not.
A Fortran derived type is interoperable if the Fortran derived-type definition is given the BIND attribute explicitly. For example:
TYPE, BIND(C) :: MYFTYPE . . END TYPE MYFTYPENote that the derived type C_PTR is interoperable with any C data pointer and C_FUNPTR is interoperable with any C function pointer type. A Fortran derived type is interoperable with a C struct type if they have the same number of components, and the components of the Fortran derived type have types and type parameters that are interoperable with the types of the corresponding components of the C struct type. A component of a Fortran derived type and a component of a C struct type correspond if they are declared in the same relative position in their respective type definitions.
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
The names of the corresponding components of the derived type and the C struct type need not be the same.
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: