/GNU Fortran 7

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 support the array descriptor (dope vector) as specified in the Technical Specification, but uses an array descriptor with different fields. 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 and C_F_POINTER intrinsics.
  • The OPTIONAL attribute is now allowed for dummy arguments; an absent argument matches a NULL pointer.
  • Assumed types (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.

  • 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 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:

  • 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: , Up: Interoperability with C [Contents][Index]

© Free Software Foundation
Licensed under the GNU Free Documentation License, Version 1.3.