7.7. Interoperable Enumerations

A Fortran enumeration that uses the BIND(C) attribute and the C_INT kind type parameter for its members is interoperable with a C function, function argument, or global variable of type enum. The Fortran object will be interoperable with any C type derived from the C type. The compiler ensures that the Fortran integer type that you select is compatible with the integer type used by the corresponding C enumeration.

The following example is interoperable:


/* C variable */
enum COLORS = {RED, GREEN, BLUE = 6};

USE ISO_C_BINDING
ENUM, BIND(C) :: COLORS
      ENUMERATOR :: RED, BLUE
      ENUMERATOR GREEN = 6
END ENUM

For more information about Fortran enumerations, refer to Fortran Language Reference Manual, Volume 1.