Technical data

30
Chapter 3: Fortran Program Interfaces
Fortran/C Interface
When writing Fortran programs that call C functions, consider procedure
and function declaration conventions for both languages. Also, consider the
rules for argument passing, array handling, and accessing common blocks
of data.
Procedure and Function Declarations
This section discusses items to consider before calling C functions from
Fortran.
Names
When calling a Fortran subprogram from C, the C program must append an
underscore (_) to the name of the Fortran subprogram. For example, if the
name of the subprogram is matrix, then call it by the name matrix_. When
Fortran is calling a C function, the name of the C function must also end with
an underscore.
The Fortran compiler changes all its subprogram names to lowercase. Thus,
all of the following subprograms refer to the same function matrix when
interfacing with C:
subroutine MATRIX
subroutine Matrix
subroutine matrix
The exception to this rule is when the u option to f77 is used. This option
causes case to be preserved.