cfortran64-bit

Definitive length of primitive C and Fortran types


I am currently revamping the native bindings for BLAS/LAPACK (Fortran libraries) for all major OS on 32/64 bit as a Java library: netlib-java.

However, I've started to hit some problems to do with data type differences between the UNIX/Windows world, and between Fortran / C.

Tables of Fortran and C data types are pretty non-commital because sizes are not explicitly defined by the C language.

Is there a canonical source (or can we create one by referencing authoritative sources?) of all the bit sizes IN PRACTICE of the primitive data types on major OSes for both Fortran and C?

Or, at the very least, the Fortran types in terms of the C types.

i.e. populate a table with the following columns (with a few to begin):

OS      ARCH    Language Type             Bits
Linux   x86_64  C        int              32
Linux   x86_64  C        long             64
Linux   x86_64  C        float            32
Linux   x86_64  C        double           64
Linux   x86_64  Fortran  LOGICAL          32
Linux   x86_64  Fortran  INTEGER          32
Linux   x86_64  Fortran  REAL             32
Linux   x86_64  Fortran  DOUBLE PRECISION 64
Linux   x86_64  Java JNI jint             32
Windows x86_64  Fortran  INTEGER          32
Windows x86_64  Java JNI jint             64
...

(I'm not sure if this is correct)

It is possible to lookup the Java types in terms of C primitives in the jni_md.h which is shipped with every JDK.


Solution

  • As noted by @cup in the comments, there is an ISO_C_BINDING standard. That gives us a level of comfort (at least with GCC) that the mappings as noted in the CBLAS/LAPACKE C API (which uses basic C types) are portable across architectures with that compiler. As noted in the question, this is about bit sizes in practice, not some abstract concept of what the languages guarantee. i.e.

    and then it's up to C to define the byte sizes of the primitive types and up to the jni_md.h to define the Java primitive types.

    In practice, this means that the only disconnect is that on 64 bit Windows long is 32 bit (64 bit on 64 bit Linux) and jint is defined in terms of long. Therefore the compiler complains about jint*/int type conversions during Windows builds that can be safely ignored.