This section discusses implementation-specific ways to call C procedures from a Fortran program.
By default, the Fortran compiler converts function and subprogram names to lower case, and adds a trailing underscore. The C compiler never performs case conversion. A C procedure called from a Fortran program must, therefore, be named using the appropriate case. For example, consider the following calls:
CALL PROCNAME() |
The C procedure must be named procname_. |
x=fnname() |
The C procedure must be named fnname_. |
In the first call, any value returned by procname is ignored. In the second call to a function, fnname must return a value.
By default, Fortran subprograms pass arguments by reference; that is, they pass a pointer to each actual argument rather than the value of the argument. C programs, however, pass arguments by value. Consider the following:
When a Fortran program calls a C function, the C function's formal arguments must be declared as pointers to the appropriate data type.
When a C program calls a Fortran subprogram, each actual argument must be specified explicitly as a pointer.
When C code needs to use a common block declared in Fortran, an underscore (_) must be appended to its name, see below.
Fortran code |
C code |
This example demonstrates defining a COMMON block in Fortran for Linux, and accessing the values from C.
Fortran code |
C code |