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:
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. C_LOC
and C_F_POINTER
intrinsics. OPTIONAL
attribute is now allowed for dummy arguments; an absent argument matches a NULL
pointer. TYPE(*)
) have been added, which may only be used for dummy arguments. They are unlimited polymorphic but contrary to CLASS(*)
they do not contain any type information, similar to C’s void *
pointers. Expressions of any type and kind can be passed; thus, it can be used as replacement for TYPE(C_PTR)
, avoiding the use of C_LOC
in the caller. Note, however, that TYPE(*)
only accepts scalar arguments, unless the DIMENSION
is explicitly specified. As DIMENSION(*)
only supports array (including array elements) but no scalars, it is not a full replacement for C_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.
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 using C_LOC
and C_F_POINTER
to scalars or arrays of a specific rank. The rank can be determined using the RANK
intrinisic. Currently unimplemented:
ISO_Fortran_binding.h
header file and the C functions it specifies are not available. 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]
© Free Software Foundation
Licensed under the GNU Free Documentation License, Version 1.3.
https://gcc.gnu.org/onlinedocs/gcc-10.2.0/gfortran/Further-Interoperability-of-Fortran-with-C.html