Previous: Working with Pointers, Up: Interoperability with C [Contents][Index]
7.1.6 Further Interoperability of Fortran with C
The Technical Specification ISO/IEC TS 29113:2012 on further
interoperability of Fortran with C extends the interoperability support
of Fortran 2003 and Fortran 2008. Besides removing some restrictions
and constraints, it adds assumed-type (TYPE(*)
) and assumed-rank
(dimension
) variables and allows for interoperability of
assumed-shape, assumed-rank and deferred-shape arrays, including
allocatables and pointers.
Note: Currently, GNU Fortran does not use internally the array descriptor (dope vector) as specified in the Technical Specification, but uses an array descriptor with different fields. Assumed type and assumed rank formal arguments are converted in the library to the specified form. The ISO_Fortran_binding API functions (also Fortran 2018 18.4) are implemented in libgfortran. Alternatively, the Chasm Language Interoperability Tools, http://chasm-interop.sourceforge.net/, provide an interface to GNU Fortran’s array descriptor.
The Technical Specification adds the following new features, which are supported by GNU Fortran:
- The
ASYNCHRONOUS
attribute has been clarified and extended to allow its use with asynchronous communication in user-provided libraries such as in implementations of the Message Passing Interface specification. - Many constraints have been relaxed, in particular for
the
C_LOC
andC_F_POINTER
intrinsics. - The
OPTIONAL
attribute is now allowed for dummy arguments; an absent argument matches aNULL
pointer. - Assumed types (
TYPE(*)
) have been added, which may only be used for dummy arguments. They are unlimited polymorphic but contrary toCLASS(*)
they do not contain any type information, similar to C’svoid *
pointers. Expressions of any type and kind can be passed; thus, it can be used as replacement forTYPE(C_PTR)
, avoiding the use ofC_LOC
in the caller.Note, however, that
TYPE(*)
only accepts scalar arguments, unless theDIMENSION
is explicitly specified. AsDIMENSION(*)
only supports array (including array elements) but no scalars, it is not a full replacement forC_LOC
. On the other hand, assumed-type assumed-rank dummy arguments (TYPE(*), DIMENSION(..)
) allow for both scalars and arrays, but require special code on the callee side to handle the array descriptor. - Assumed-rank arrays (
DIMENSION(..)
) as dummy argument allow that scalars and arrays of any rank can be passed as actual argument. As the Technical Specification does not provide for direct means to operate with them, they have to be used either from the C side or be converted usingC_LOC
andC_F_POINTER
to scalars or arrays of a specific rank. The rank can be determined using theRANK
intrinisic.
Currently unimplemented:
- GNU Fortran always uses an array descriptor, which does not
match the one of the Technical Specification. The
ISO_Fortran_binding.h
header file and the C functions it specifies are not available. - Using assumed-shape, assumed-rank and deferred-shape arrays in
BIND(C)
procedures is not fully supported. In particular, C interoperable strings of other length than one are not supported as this requires the new array descriptor.
Previous: Working with Pointers, Up: Interoperability with C [Contents][Index]