The table below shows the simple correspondence between the type of the Fortran actual argument and the type of the C procedure argument for arrays of types INTEGER, INTEGER*2, REAL, DOUBLE PRECISION, and LOGICAL.
Note
There is no simple correspondence between Fortran automatic, allocatable,
adjustable, or assumed size arrays and C arrays. Each of these types of
arrays requires a Fortran array descriptor, which is implementation-dependent.
Fortran Type |
C Type |
integer x( ) |
int x[ ]; |
integer*1 x( ) |
signed char x[ ]; |
integer*2 x( ) |
short x[ ]; |
integer*4 x( ) |
long int x[ ]; |
integer*8 x( ) |
long long x[ ]; or _int64 |
real*4 x( ) |
float x[ ]; |
real*8 x( ) |
double x[ ]; |
real x( ) |
float x[ ]; |
real*16 x( ) |
No equivalent |
double precision x( ) |
double x[ ]; |
logical*1 x( ) |
char x[ ]; |
logical*2 x( ) |
short int x[ ]; |
logical*4 x( ) |
long int x[ ]; |
logical x( ) |
int x[ ]; |
logical*8 x( ) |
long long x[ ]; or _int64 x[ ]; |
complex x( ) |
struct {float real, imag;} [x]; |
complex *8 x( ) |
struct {float real, imag;} [x]; |
complex *16 x( ) |
struct {double dreal,dimag;} x; |
double complex x( ) |
struct { double dreal,dimag; } [x]; |
complex(KIND=16) x( ) |
No equivalent |
Note
Be aware that array arguments in the C procedure do not need to be declared
as pointers. Arrays are always passed as pointers.
Note
When passing arrays between Fortran and C, be aware of the following semantic
differences:
Fortran organizes arrays in column-major order (the first subscript, or dimension, of a multiply-dimensioned array varies the fastest); C organizes arrays in row-major order (the last dimension varies the fastest).
Fortran array indices start at 1 by default; C indices start at 0. Unless you declare the Fortran array with an explicit lower bound, the Fortran element X(1) corresponds to the C element x[0].
Example below shows the Fortran code for passing an array argument to C and the corresponding C code.
Fortran Code |
Corresponding C Code |