To be able to write C procedures that call or are called by Fortran procedures, it is necessary to know the conventions for procedure names, data representation, return values, and argument lists that the compiled code obeys.
On UNIXsystems, the name of a common block or a Fortran procedure has an underscore appended to it by the compiler to distinguish it from a C procedure or external variable with the same user-assigned name. Fortran library procedure names have embedded underscores to avoid clashes with user-assigned subroutine names.
The following is a table of corresponding Fortran and C declarations:
Fortran C
integer*2 x short int x;
integer x long int x;
logical x long int x;
real x float x;
double precision x double x;
complex x struct { float r, i; } x;
double complex x struct { double dr, di; } x;
character*6 x char x[6];
(By the rules of Fortran,
integer,
logical,
and
real
data occupy the same amount of memory).
A function of type integer, logical, real, or double precision declared as a C function that returns the corresponding type. A complex or double complex function is equivalent to a C routine with an additional initial argument that points to the place where the return value is to be stored. Thus,
All Fortran arguments are passed by address. In addition, for every argument that is of type character or that is a dummy procedure, an argument giving the length of the value is passed. (The string lengths are long int quantities passed by value). The order of arguments is then: