Sun Studio 12: Fortran Programming Guide

11.8 Alternate Returns

Fortran 77’s alternate returns mechanism is obsolete and should not be used if portability is an issue. There is no equivalent in C to alternate returns, so the only concern would be for a C routine calling a Fortran routine with alternate returns. Fortran 95 will accept Fortran 77 alternate returns, but its use should be discouraged.

The implementation returns the int value of the expression on the RETURN statement. This is implementation dependent and its use should be avoided.

Table 11–17 Alternate Returns

C calls Fortran  

Running the Example  


int altret_ ( int * );
main ()
{
  int k, m ;
  k =0;
  m = altret_( &k ) ;
  printf( "%d %d\n", k, m);
}

------------------------------

SUBROUTINE ALTRET( I, *, *)
  INTEGER I
  I = I + 1
  IF(I .EQ. 0) RETURN 1
  IF(I .GT. 0) RETURN 2
  RETURN
END

demo% cc -c tst.c
demo% f95 -o alt alt.f tst.o
alt.f:
altret:
demo% alt
1 2

The C routine receives the return value 2 from the Fortran routine because it executed the RETURN 2 statement.