Character and aggregate data
Most numeric data types have counterparts across C/C++ and Fortran. However, character and aggregate data types require
special treatment:
- C character strings are delimited by a '\0'character.
In Fortran, all character variables and expressions have a length that is
determined at compile time. Whenever Fortran passes a string argument to another
routine, it appends a hidden argument that provides the length
of the string argument. This length argument must be explicitly declared
in C. The C code should not assume a null terminator; the supplied or declared
length should always be used.
- C stores array elements in row-major order (array elements in the same
row occupy adjacent memory locations). Fortran stores array elements in ascending
storage units in column-major order (array elements in the same column occupy
adjacent memory locations). Table 8 shows how a two-dimensional
array declared by A[3][2] in C and by A(3,2) in Fortran, is stored:
Table 8. Storage of a two-dimensional array
Storage unit |
C and C++ element
name |
Fortran element name |
Lowest |
A[0][0] |
A(1,1) |
|
A[0][1] |
A(2,1) |
|
A[1][0] |
A(3,1) |
|
A[1][1] |
A(1,2) |
|
A[2][0] |
A(2,2) |
Highest |
A[2][1] |
A(3,2) |
- In general, for a multidimensional array, if you list the elements of
the array in the order they are laid out in memory, a row-major array will
be such that the rightmost index varies fastest, while a column-major array
will be such that the leftmost index varies fastest.