FIX: Application Evaluates Array Expression Incorrectly

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

The information in this article applies to:

  • Microsoft FORTRAN for MS-DOS, versions 4.0, 4.01, 4.1, 5.0, 5.1
  • Microsoft FORTRAN for OS/2, versions 4.1, 5.0, 5.1

SYMPTOMS

An application that assigns an expression to an array element produces incorrect results.

CAUSE

The application uses the READ statement to enter the array element index. The optimizer in the code generator performs common subexpression elimination and generates incorrect code for the array expression.

RESOLUTION

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

  • Specify the -Odlt compiler option switch to disable the common subexpression elimination optimization.
  • Store the array index in a temporary variable and specify the variable as the array index in the expression.

STATUS

Microsoft has confirmed this to be a problem in FORTRAN versions 4.0, 4.01, 4.1, 5.0, and 5.1 for MS-DOS and 4.1, 5.0, and 5.1 for OS/2. This problem was corrected in FORTRAN PowerStation, version 1.0.

MORE INFORMATION

In the first code example below, because the compiler treats the expression X(I) as a common subexpression, it generates code to evaluate the expression C = A / B for the expression C = X(I). The second example uses a temporary variable to eliminate the common subexpression.

Sample Code #1

C Compile options needed: None

      REAL X(10)
      READ (*, *) I, A, B
      X(I) = A / B
      A = B
      C = X(I)
      WRITE (*, *) C
      END

Sample Code #2

C Compile options needed: None

      REAL X(10)
      READ (*, *) I, A, B
      X(I) = A / B
      A = B
      J = I
      C = X(J)
      WRITE (*, *) C
      END


Additional reference words: 4.00 4.01 4.10 5.00 5.10
KBCategory: kbtool kbfixlist kbbuglist
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.