Technical data

36
Chapter 3: Fortran Program Interfaces
When a C routine uses an array passed by a Fortran subprogram, the
dimensions of the array and the use of the subscripts must be interchanged,
as shown in Figure 3-1.
Figure 3-1 Array Subscripts
The Fortran caller prints out the value 99. Note the following:
Because arrays are stored in column-major order in Fortran and row-
major order in C, the dimension and subscript specications are
reversed.
Because the lower-bound default is 1 for Fortran and 0 for C, 1 must be
subtracted from the indexes in the C routine. Also, because Fortran
passes parameters by reference, *j and *p are pointers in the C routine.
Accessing Common Blocks of Data
The following rules apply to accessing common blocks of data:
Fortran common blocks must be declared by common statements; C
can use any global variable. Note that the common block name in C
(sam_) must end with an underscore.
Data types in Fortran and C programs must match unless you want
equivalencing. If so, you must adhere to the alignment restrictions for
the data types described in Chapter 2.
Fortran caller
integer a(2,3)
call p (a, 1, 3)
write (6, 10) a(1, 3)
10 format (1x, I6)
stop
end
C called routine
void
p_(a, i, j)
int *i, *j, a[3] [3]
{ a[*j-1] [*i-1] = 99;
}
A.
B.
j and i are pointers to integers.
Dimensions and subscripts are reversed.
1 is subtracted from the indices.