FIX: Logical IF in GOTO Loop Produces Unexpected Results

Last reviewed: September 11, 1997
Article ID: Q49731
4.00 4.10 5.00 5.10 | 4.10 5.00 5.10
MS-DOS              | OS/2
kbtool kbbuglist kbfixlist

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 reference words: 4.00 4.10 5.00 5.10 label run run-time
buglist4.00 buglist4.10 buglist5.00 buglist5.10 fixlist1.00
KBCategory: kbtool kbbuglist kbfixlist
KBSubCategory: FLIss
Solution Type : kbfix


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 11, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.