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)
?
Depends on your idea of "practical compiler", I guess.
Neither the C standard nor the Fortran standard require IEEE conformance, but most[citation needed] compilers adhere to it (as do most processors, so this is as much a matter of optimization as it is of conformance). Cray and VAX processors are the notable exceptions, so you may find a compiler for those systems that conforms to the processor's implementation of float instead. (e.g., on a Cray, a float is 8 bytes).
For more: http://www.quadibloc.com/comp/cp0201.htm