Intel® Fortran Compiler XE 13.1 User and Reference Guides
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 first argument is a pointer to the location where the called procedure should store the result.
The second is the maximum number of characters that must be returned, padded with blank spaces if necessary.
The called routine must copy its result through the address specified in the first argument. The following example shows the Fortran code for a return character function called MAKECHARS and a corresponding C routine.
Example of Returning Character Types from C to Fortran
Fortran code
interface function makechars(x,y) !DEC$ATTRIBUTES decorate, alias:'makechars'::makechars character*10 makechars double precision x,y end function end interface character *10 chars double precision x,y chars=makechars(x,y)
Corresponding C Routine
void makechars (char *result, size_t length, double *x, double *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:
The function's length and result do not appear in the call statement; they are added by the compiler.
The called routine must copy the result string into the location specified by result; it must not copy more than length characters.
If fewer than length characters are returned, the return location should be padded on the right with blanks; Fortran does not use zeros to terminate strings.
The called procedure is type void.