FIX: Incorrect Results from Alternate Returns and $STORAGE:2 (77557)



The information in this article applies to:

  • Microsoft FORTRAN Compiler for MS-DOS 5.1
  • Microsoft FORTRAN compiler for OS/2 5.1

This article was previously published under Q77557

SYMPTOMS

Microsoft FORTRAN code that uses alternate RETURNS and is compiled with $STORAGE:2 metacommand in the called subprogram and $STORAGE:4 (the default) in the calling routine may not return to the correct alternate return label number. This will cause incorrect results.

CAUSE

When the $STORAGE:2 metacommand is in the separately compiled subroutine with the alternate return, the AX register is correctly initialized with the return code but the DX register is not correctly initialized (zeroed), resulting in incorrect operation of the calling program. There is a CWD (convert to double word using DX:AX) missing in the generated code for the called subprogram. The calling routine acts on the fact that DX is not zero and branches to the next executable statement and not the correct alternate return label.

STATUS

Microsoft has confirmed this to be a problem in the products listed above. This problem was corrected in FORTRAN PowerStation.

MORE INFORMATION

The following code reproduces the problem:

Calling routine (in separate file):

      PROGRAM TEST

      CALL SUB1(*90)
      PRINT *, 'ERROR - NORMAL RETURN'
      STOP

90    PRINT *, 'CORRECT - ALTERNATE RETURN'
      STOP
      END
				

Called subprogram (in separate file):

$STORAGE:2
      SUBROUTINE SUB1(*)
      RETURN 1
      END
				

Modification Type:MajorLast Reviewed:10/23/2003
Keywords:KB77557