FIX: Logical IF in GOTO Loop Produces Unexpected Results

ID: Q49731


The information in this article applies to:
  • Microsoft FORTRAN for MS-DOS, versions 4.0, 4.1, 5.0, 5.1
  • Microsoft FORTRAN for OS/2, versions 4.1, 5.0, 5.1


SYMPTOMS

In an application compiled with Microsoft FORTRAN, a logical IF statement in a GOTO loop produces incorrect results.


CAUSE

The compiler incorrectly optimized the IF statement in the GOTO loop.


RESOLUTION

To address this problem, perform one of the following two steps:

  • Specify the -Od compiler option switch to disable optimizations.


  • If optimization is required, modify the source code to change the logical IF statement to a standard IF statement. For example, change the following code:
    
          if (j .GE. 3) GOTO 3100    ! logical IF statement 
    to the following code:
    
          if (j .GE. 3) then         ! standard IF statement
             GOTO 3100
          endif 



STATUS

Microsoft has confirmed this to be a problem in FORTRAN versions 4.0, 4.1, 5.0, and 5.1. This problem was corrected in FORTRAN PowerStation, version 1.0.


MORE INFORMATION

As shown in the code sample below, the logical IF and GOTO loop compiles and runs without errors but it does not execute the correct lines of code. Because the GOTO 3100 statement in the logical IF statement is ignored, the program prints "at 3200, loop failed."

To address this problem, compile the application without optimizations. The logical IF statement works correctly and the program prints "at 3100, loop worked".

Sample Code


C Compile options needed: See above

      J = 0
3190  CONTINUE
      IF (J .GE. 3) GOTO 3100       ! The logical IF
      J = J + 1
      GOTO 3190                     ! The Goto loop
3200  CONTINUE
      WRITE (*, *) 'at 3200, loop failed'
      STOP
3100  CONTINUE
      WRITE (*, *) 'at 3100, loop worked'
      STOP
      END 

Additional query words: 4.00 4.10 5.00 5.10 label run run-time buglist4.00 buglist4.10 buglist5.00 buglist5.10 fixlist1.00

Keywords :
Version : :4.0,4.1,5.0,5.1
Platform :
Issue type :


Last Reviewed: November 2, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.