Intel® Fortran Compiler 17.0 Developer Guide and Reference

Data Types Overview

While Fortran and C each support many of the same basic data types, there are no direct correlations.

One difference is that Fortran has the concept of "kinds;" C treats these distinct types. For example, consider the Fortran INTEGER type. C has numerous integer types, from short int to long long int, and some specialty types such as intptr_t. These may or may not have corresponding kinds in Fortran. For each of the C integer types that might be interoperable, ISO_C_BINDING declares a named constant (PARAMETER) giving the kind number for the implementation's equivalent INTEGER kind.

Consider the simple C int type. This corresponds to INTEGER(C_INT), where C_INT is defined in ISO_C_BINDING. In Intel® Fortran, the value is always four (4), as a C int corresponds with Fortran INTEGER(4). However, other Fortran implementations may use different kind numbers; using the named constant ensures portability.

Now consider the C intptr_t type. This is an integer that is large enough to hold a pointer (address). In Intel® Fortran, this is INTEGER(4) when building a 32-bit application and INTEGER(8) when building a 64-bit application. Intel® Fortran provides different copies of ISO_C_BINDING for various platforms.

Fortran has no unsigned integer types, so there are no constants for C unsigned types. Such types are not interoperable.

If there is a "kind" of C type not supported by the Fortran implementation, the named constant for that type is defined as -1, which will generate a compile-time error if you try to use it.

Similarly, there are constants defined for REAL, COMPLEX, LOGICAL and CHARACTER. For REAL, the standard offers the possibility of a C long double type. This is implemented in different ways by various C compilers on various platforms supported by Intel® Fortran.

LOGICAL and CHARACTER need special treatment for interoperability. The Fortran standard states that LOGICAL corresponds to the (ISO_C_BINDING) C _Bool type, and defines a single kind value C_BOOL, which is 1 in Intel® Fortran. By default, Intel® Fortran, tests LOGICALs for true/false differently than C does. Where C uses zero for false and not-zero for true, Intel® Fortran defaults to using -1 (all bits set) as true and zero as false. If you are going to use LOGICAL types to interoperate with C, be sure to specify the option fpscomp[:]logicals, which changes the interpretation to be C-like. This is included if you use the option standard-semantics, which is recommended any time you use Fortran 2003 (or later) features.

In terms of CHARACTER, C does not have character strings. It has arrays of single characters, so this is how you must represent strings in Fortran. There is a kind value defined, C_CHAR, corresponding to the C char type. Only character variables with length of one (1) are interoperable. For further discussion, see Procedures

Derived types can also be interoperable. For additional information and restrictions, see Derived Types.

See Also