Intel® Fortran Compiler 16.0 User and Reference Guide

Interoperating with arguments using C descriptors

These are facilities for interoperable procedure interfaces that specify dummy arguments that are assumed-shape arrays, have assumed character length, or have the ALLOCATABLE, POINTER, or OPTIONAL attributes.

Assumed-rank

An assumed-rank object is a dummy variable whose rank is assumed from its actual argument. This facilitates interoperability with C functions that can accept arguments of arbitrary rank. The intrinsic function, RANK, can be used to obtain the rank of an assumed-rank variable.

A procedure must have an explicit interface if it has a dummy argument that is assumed-rank.

The SHAPE, SIZE, and UBOUND intrinsic functions are defined for an assumed-rank array that is associated with an assumed-size array.

An assumed-rank dummy argument may correspond to an actual argument of any rank. If the actual argument has rank zero, the dummy argument has rank zero; the shape is a zero-sized array and the LBOUND and UBOUND intrinsic functions, with no DIM argument, return zero-sized arrays. If the actual argument has rank greater than zero, the rank and extents of the dummy argument are assumed from the actual argument, including no final extent for an assumed-size array. If the actual argument is an array and the dummy argument has the ALLOCATABLE or POINTER attribute, the bounds of the dummy argument are assumed from the actual argument.

Assumed-type

An assumed-type object is a dummy variable declared as TYPE(*). This simplifies interoperability with C formal parameters of type (void *).

An explicit interface is required for a procedure that has a dummy argument that is assumed-type because an assumed-type dummy argument is polymorphic.

An assumed-type dummy argument must not correspond to an actual argument that is of derived type with type parameters, type-bound procedures, or final subroutines.

CFI_cdesc

A C descriptor is a C structure of type CFI_cdesc that is defined in the file ISO_Fortran_binding.h.

Restrictions for BIND(C)

If BIND(C) is specified for a procedure, each dummy argument must be an interoperable procedure or a variable that is interoperable, assumed shape, assumed rank, assumed type, of assumed character length, or has the ALLOCATABLE or POINTER attribute. If BIND(C)is specified for a function, the function result must be an interoperable scalar variable.

A dummy argument of a procedure that is BIND(C) must not have both the OPTIONAL and VALUE attributes.

A variable that is a dummy argument of a procedure that is BIND(C) must be of interoperable type or assumed type.

A coarray shall not be a dummy argument of a BIND(C) procedure.

The ALLOCATABLE or POINTER attribute must not be specified for a default-initialized dummy argument of a BIND(C) procedure.

Further Requirements

Variables with the ASYNCHRONOUS attribute can be used for asynchronous communications between Fortran and C procedures.

When a Fortran procedure that has an INTENT (OUT) allocatable dummy argument is invoked by a C function, and the actual argument in the C function is the address of a C descriptor that describes an allocated allocatable variable, the variable is deallocated on entry to the Fortran procedure. When a C function is invoked from a Fortran procedure via an interface with an INTENT (OUT) allocatable dummy argument, and the actual argument in the reference to the C function is an allocated allocatable variable, the variable is deallocated on invocation (before execution of the C function begins).

ISO_Fortran_binding.h

The types, macros, and functions declared in ISO_Fortran_binding.h can be used by a C function to interpret C descriptors and allocate and deallocate objects represented by C descriptors. These provide a means to specify a C prototype that interoperates with a Fortran interface that has an allocatable, assumed character length, assumed-rank, assumed-shape, or data pointer dummy argument.

The ISO_Fortran_binding.h is a C header file that contains these definitions:

Restrictions on C functions interoperating with Fortran procedures

Any C function inter-operating with Fortran procedures must meet these restrictions:

See Also