Intel® Fortran Compiler 17.0 Developer Guide and Reference
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 |
---|
|
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 |
---|
|
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 |
---|
|
Alternatively, the declaration for y can be specified as a C_PTR passed by value:
Passing Pointer by Value Example |
---|
|