# Data Types

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

One difference is that Fortran has the concept of kinds. C treats these kinds as distinct types. For example, the Fortran INTEGER. C has integer types that range from `short int` to `long long int`, and has specialty types such as `intptr_t`. Fortran may not have a corresponding kind. For each interoperable C `integer` type, the ISO_C_BINDING declares a named constant (PARAMETER) that gives 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 the ISO_C_BINDING. In Intel® Fortran, the value is always four, as a C `int` corresponds with Fortran INTEGER(4). Other Fortran implementations may use different kind numbers. Using the named constant ensures portability.

Now consider the C `intptr_t` type. This integer is large enough to hold a pointer (address). In Intel® Fortran, this corresponds to INTEGER(C_INTPTR_T). It is INTEGER(4) when building a 32-bit application, and INTEGER(8) when building a 64-bit application.

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

If there is a kind of C type that is not supported by the Fortran implementation, the named constant for that type is defined as -1 and generates a compile-time error if used.

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.

- GCC* on 32-bit Linux*: The `long double` is an 80-bit floating type, as supported by the X87 instruction set. It is not supported by Intel® Fortran, so the C_LONG_DOUBLE is -1.
- GCC on macOS: The C_LONG_DOUBLE is defined as 16.
- Windows*: The `long double` is treated the same as a `double`, so the C_LONG_DOUBLE is defined as 8.
- 64-bit Linux*: The C_LONG_DOUBLE is defined as 16.

  For Intel's DPC++ and C/C++ compilers, `long double` by default is an 80-bit extended precision floating-point type. C/C++ files containing `long double` data types that interoperate with Fortran should be compiled with the GCC option `-mlong-double-128` to force long double variables to 128-bit quad precision. Intel's Fortran compilers do not support an 80-bit extended precision data type.

### Note

- Use the constants for kind values and the corresponding types in C to ensure matching.
- In Intel® C/C++ on Linux*, a `long double` can be forced to be a 128-bit IEEE format floating-point data type using the `-mlong-double-128` command line option. On all platforms, Intel® C/C++ supports `__float128` in the source code. On Windows*, Intel® C/C++ supports the `_Quad` type in the source code by using the command line option, `/Qoption,cpp,--extended_float_types`.

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 of 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, specify the option fpscomp[:]logicals to change the interpretation to be C-like. This is included when using the option standard-semantics, which is recommended for using Fortran 2003 (or later) features. C does not have character strings. It has arrays of single characters, and this is how strings in Fortran must be represented. There is a kind value defined as C_CHAR, which corresponds to the C `char` type. Only character variables with a length of one are interoperable. See Procedures for more information.

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

Parent topic: Standard Tools for Interoperability

- Scalar Types
- Characters
- Pointers
- Derived Types

## See Also

Procedures
Derived Types