Technical data

Fortran/C Interface
31
Note that only one main routine is allowed per program. The main routine
can be written in either C or Fortran. Table 3-1 contains an example of a C
and a Fortran main routine.
Invocations
Invoke a Fortran subprogram as if it were an integer-valued function whose
value species which alternate return to use. Alternate return arguments
(statement labels) are not passed to the subprogram but cause an indexed
branch in the calling subprogram. If the subprogram is not a function and
has no entry points with alternate return arguments, the returned value is
undened. The Fortran statement
call nret (*1,*2Ex,*3)
is treated exactly as if it were the computed goto
goto (1,2,3), nret()
A C function that calls a Fortran subprogram can usually ignore the return
value of a Fortran subroutine; however, the C function should not ignore the
return value of a Fortran function. Table 3-2 shows equivalent function and
subprogram declarations in C and Fortran programs.
Table 3-1 Main Routines
C Fortran
main () {
printf("hi!\n");
}
write (6,10)
10 format ('hi!')
end
Table 3-2 Equivalent C and Fortran Function Declarations
C Function Declaration Fortran Function Declaration
double dfort() double precision function dfort()
double rfort() real function rfort()
int ifort() integer function ifort()
int lfort logical function lfort()