Technical data

32
Chapter 3: Fortran Program Interfaces
Note the following:
Avoid calling Fortran functions of type FLOAT, COMPLEX, and
CHARACTER from C.
You cannot write a C function so that it will return a COMPLEX value
to Fortran.
A character-valued Fortran subprogram is equivalent to a C language
routine with two extra initial arguments: a data address and a length.
However, if the length is one, no extra argument is needed and the
single character result is returned as in a normal numeric function.
Thus
character*15 function g()
is equivalent to
char result [1];
long int length;
g_(result, length, )
and could be invoked in C by
char chars[15]
g_(chars, 15, );
and
character function h()
could be invoked in C by
char c, h();
c=h_();
Arguments
The following rules apply to arguments passed between Fortran and C:
All explicit arguments must be passed by reference. All routines must
specify an address rather than a value. Thus, to pass constants or
expressions to Fortran, the C routine must rst store their values into
variables and then pass the address of the variable. (The only exception
occurs when passing the length of a string from C to a Fortran
subroutine with a parameter of type CHARACTER.)