For interoperability with C programs, the 2003 revision of the Fortran standard introduced a module iso_c_binding
, which allows one to write things like this:
USE iso_c_binding, ONLY: c_int, c_float
INTEGER(KIND=c_int) :: x
REAL(KIND=c_float) :: y
which is guaranteed to map exactly to a int x
and a float y
on the C-side. Now for integers, this is crucial since the default INTEGER
type may (depending on compiler and platform) very well wrap to a 64-bit integer type even when int
is 32-bit.
However, for floating point types, the following mappings seem almost unavoidable:
REAL*4 (or) REAL -> float
REAL*8 (or) DOUBLE PRECISION -> double
So here's the question: Is there any practical platform or compiler where this is not satisfied, e.g., where sizeof(REAL*4) != sizeof(float)
?