Return Values

A Fortran subroutine is a C function with a void return type. A C procedure called as a function must return a value whose type corresponds to the type the Fortran program expects (except for character, complex, and double-complex data types). The table below shows this correspondence.

Return Value Data Type

Fortran Type

C Type

integer

int;

integer*1

signed char;

integer*2

short;

integer*4

long int x;

integer*8 x

long long x; or _int64

logical

int;

logical*1

char;

logical*2

short;

logical*4x

long int x;

logical*8

long long x; or _int64

real

float;

real*r x

float x;

real*8 x

double x;

real*16

No equivalent

double precision

double;

Example below shows Fortran code for a return value function called cfunct and the corresponding C routine.

Example of Returning Values from C to Fortran

Fortran code
integer iret, cfunct  
iret = cfunct()

Corresponding C Routine
int cfunct ()
{
...program text...
return i;
}