Intel® Fortran Compiler 16.0 User and Reference Guide

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

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 above function has the binding label func. You can specify an alternative binding label as follows:

Alternate Binding Label Example

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

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

Call to C Function Example

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:

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:

Passing Pointer by Value Example

type (C_PTR), value :: y