Returning Character Data Types

If a Fortran program expects a function to return data of type character, the Fortran compiler adds two additional arguments to the beginning of the called procedure's argument list:

The called routine must copy its result through the address specified in the first argument. Example that follows shows the Fortran code for a return character function called makechars and corresponding C routine.

Example of Returning Character Types from C to Fortran

Fortran code
character*10 chars, makechars
double precision x, y  
chars = makechars( x, y )

Corresponding C Routine
void makechars_ ( result, length, x, y );
char *result;
int length;
double *x, *y;
{
...program text, producing returnvalue...
for (i = 0;  i < length;  i++ ) {  
result[i] = returnvalue[i];  
}
}

In the above example, the following restrictions and behaviors apply: