Intel® Fortran Compiler 17.0 Developer Guide and Reference
The Intel® Fortran Compiler supports the Fortran standardized mechanism for allowing Fortran code to reliably communicate (or interoperate) with C code.
This mechanism includes a group of features for C interoperability, enabling mixed-language programming in a more portable manner.
The Fortran standard discusses interoperability in terms of a "companion C processor." Each Fortran implementation is free to choose which C is its companion. Although the standard explicitly specifies a companion C (not C++) processor, you can use C++, as long as you use features that are compatible with C when interoperating with Fortran.
For Intel® Fortran, the supported C companion is the Intel® C++ Compiler or the Microsoft* Visual C++* Compiler on Windows*, and the Intel® C++ Compiler or gcc* on Linux* and OS X*.
The core principle of interoperability is that something should work the same way in Fortran as it does in C. In terms of interoperability, the following applies:
Fortran provides a way to reference procedures that are defined by the C programming language or procedures that are described by C prototypes, even if they are not actually defined by means of C.
Conversely, a procedure defined by a Fortran subprogram can be referenced by a function defined by means of C.
In addition, you can define global variables that are associated with C variables whose names have external linkage.
You can also declare Fortran variables, data structures and enumerations that correspond to similar declarations in C.
The following sections describe interoperability requirements for types, variables, procedures, and global data.
The following example calls a C function.
C Function Prototype Example |
---|
int C_Library_Function(void* sendbuf, int sendcount, int *recvcounts); |
Fortran Module Example |
---|
|
Fortran Calling Sequence Example |
---|
|
The following example calls a Fortran subroutine called Simulation. This subroutine corresponds to the C void function simulation.
Fortran Code Example |
---|
|
C Struct declaration Example |
---|
struct pass {int lenc, lenf; float *c, *f;}; |
C Function Prototype Example |
---|
void simulation(long alpha, double *beta, long *gamma, double delta[], struct pass *arrays); |
C Calling sequence Example |
---|
simulation(alpha, &beta, &gamma, delta, &arrays); |