Passing an alternate return code from Fortran to C

You can pass an alternate return code to a C routine from a Fortran subroutine by specifying the called Fortran subroutine in the #pragma linkage directive. The Fortran subroutine will produce an alternate return code when alternate returns are specified as dummy arguments on the SUBROUTINE statement.

In an all-Fortran application, the alternate returns provide a way to return to a point in the calling program other than to the point immediately following the CALL statement. The following example illustrates how a Fortran routine would call a Fortran subroutine to use an alternate return:
CALL FSUB (ARG1, *22, ARG2, *66)
In this example, *22 and *66 specify two labels (22 and 66) to which control can be passed rather than to the point following the CALL statement. The corresponding subroutine would be coded as follows:
SUBROUTINE FSUB (DARG1, DARG2, *, *)
When the FSUB subroutine executes the following RETURN statement, control would pass to the calling program at the second alternate return, at label 66.
RETURN 2

There is no alternate return point feature in C. However, if you specify the RETURNCODE suboption on the #pragma linkage directive in your C routine, you can use the fortrc() function to get the alternate return code from the RETURN statement in the Fortran subroutine. The fortrc() function reference applies to the call to Fortran immediately preceding it; you must not have any C code between the Fortran subroutine and the fortrc() function reference.

In the following example, the C routine calls the subroutine FSUB, whose SUBROUTINE and RETURN statements are shown above. The fortrc() function returns an alternate return code of 2.
#includes <stdlib.h>
#pragma linkage (fsub, FORTRAN, RETURNCODE)
void fsub (float, float);
int rc:
⋮
fsub(1.0,2.0);
rc=fortrc();
⋮

The RETURNCODE suboption is optional. It indicates to the C compiler that fsub is a Fortran routine returning an alternate return code. You cannot pass return code values from a called C function to a calling Fortran routine.