Fortran and C Scalar Arguments

Table that follows shows a simple correspondence between most types of Fortran and C data.

Fortran and C Language Declarations

Fortran

C

integer*1 x

char x;

integer*2 x

short int x;

integer*4 x

long int x;

integer x

long int x;

integer*8 x

long long x;
or
_int64 x;

logical*1 x

char x;

logical*2 x

short int x;

logical*4x

long int x;

logical x

long int x;

logical*8 x

long long x;
or
_int64 x;

real*4 x

float x;

real*8 x

double x;

real x

float x;

real*16

No equivalent

double precision x

double 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

character*6 x

char x[6];

Example below illustrates the correspondence shown in the table above: a simple Fortran call and its corresponding call to a C procedure. In this example the arguments to the C procedure are declared as pointers.

Example of Passing Scalar Data Types from Fortran to C

Fortran Call
integer I  
integer*2 J  
real x  
double precision d  
logical l  
call vexp( i, j, x, d, l )

C Called Procedure
void vexp_ ( int *i, short *j, float *x, double *d, int *l )
{
...program text...
}

Note
The character data or complex data do not have a simple correspondence to C types.