Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 11/07/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

Interoperability of Procedures and Procedure Interfaces

A Fortran procedure is interoperable if it has the BIND attribute.

A Fortran procedure interface is interoperable with a C function prototype if the following is true:

  • The interface has the BIND attribute

  • One of the following is true:

    • The interface describes a function whose result variable is a scalar that is interoperable with the result of the prototype.

    • The interface describes a subroutine and the prototype has a result type of void.

  • The number of dummy arguments of the interface is equal to the number of formal parameters of the prototype.

  • Any dummy argument with the VALUE attribute is interoperable with the corresponding formal parameter of the prototype.

  • Any dummy argument without the VALUE attribute corresponds to a formal parameter of the prototype that is of a pointer type, and one of the following is true:

    • The dummy argument is interoperable with an entity of the referenced type of the formal parameter.

    • The dummy argument is a nonallocatable nonpointer variable of type CHARACTER with assumed character length and the formal parameter is a pointer to the C descriptior descriptor CFI_cdesc_t.

    • The dummy argument is allocatable, assumed-shape, assumed-rank, or a pointer without the CONTIGUOUS attribute, and the formal parameter is a pointer to the C descriptior descriptor CFI_cdesc_t.

    • The dummy argument is assumed-type and not allocatable, assumed-shape, assumed-rank, or a pointer, and the formal parameter is a pointer to void.

  • Each allocatable or pointer dummy argument of type CHARACTER has deferred character length.

  • The prototype does not have variable arguments as denoted by an ellipsis (...).

In an invocation of an interoperable procedure whose Fortran interface has an assumed-shape or assumed-rank dummy argument with the CONTIGUOUS attribute, the associated effective argument can be an array that is not contiguous or it can be the address of a C descriptor for such an array.

If the procedure is invoked from Fortran or the procedure is a Fortran procedure, the Fortran processor will handle the difference in contiguity.

If the procedure is invoked from C or the procedure is a C procedure, the C code within the procedure must be able to handle the situation of receiving a discontiguous argument.

An actual argument that is absent in a reference to an interoperable procedure is indicated by a corresponding formal parameter with the value of a null pointer. An optional dummy argument that is absent in a reference to an interoperable procedure from a C function is indicated by a corresponding argument with the value of a null pointer.

The following rules also apply:

  • C functions must not invoke a function pointer whose value is the result of a reference to C_FUNLOC with a noninteroperable argument.

  • When passing an argument to a C procedure where the corresponding C formal parameter is a C descriptor, Fortran must pass a C descriptor and, on return, ensure that any updates to the C descriptor are reflected in Fortran.

  • If the interface specifies that the dummy argument is CONTIGUOUS, the passed argument (and the C descriptor’s description of that argument, if relevant) must be contiguous.

  • A Fortran procedure with BIND(C) that has a dummy argument that is assumed-length CHARACTER or is allocatable, assumed-shape, assumed-rank, or a pointer without CONTIGUOUS must accept that argument as a C descriptor and make sure that on return, the C descriptor reflects any changes made to the argument during execution of the Fortran procedure.

  • A Fortran procedure with one of the following arguments must accept that argument as a C descriptor and make sure that on return, the C descriptor reflects any changes made to the argument during execution of the Fortran procedure:

    • A dummy argument that is assumed-length CHARACTER

    • A dummy argument that is allocatable, assumed-shape, assumed-rank, or a pointer without CONTIGUOUS