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

ID 767251
Date 6/24/2024
Public

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

Document Table of Contents

Procedures

For a Fortran procedure to be interoperable with C, it must have an explicit interface and be declared with the BIND attribute, as shown in the BIND interface example:

function Func(i, j, k, l, m) BIND(C)

In the case of a function, the result must be scalar and interoperable.

A procedure has an associated binding label, which is global in scope. This label is the name recognized by the C processor and is, by default, the lower-case version of the Fortran name (plus any needed leading or trailing underscores). For example, the previous function has the binding label func. You can specify an alternative binding label as shown in the alternate binding label example:

function Func(i, j, k, l, m) BIND(C, name='myC_Func')

All arguments must be interoperable. Furthermore, you must ensure that the Fortran routine uses the VALUE attribute for scalar arguments, or that the C routine receives these scalar arguments as pointers to the scalar values. Consider the following call to this C function:

int c_func(int x, int *y);

As shown here, the interface for the Fortran call to c_func must have x passed with the VALUE attribute y should not have the VALUE attribute, since it is received as a pointer in the Fortran call example:

interface
   integer (C_INT) function C_Func(x, y) BIND(C)
     use, intrinsic :: ISO_C_BINDING
     implicit none
     integer (C_INT), value :: x
     integer (C_INT) :: y
   end function C_Func
end interface

Alternatively, the declaration for y can be specified as a C_PTR passed by value:

type (C_PTR), value :: y