FIX: SELECT on Characters Greater Than ASCII 127 Fails

Last reviewed: September 16, 1997
Article ID: Q86715
5.10 | 5.10 MS-DOS | OS/2 kbprg kbfixlist kbbuglist kbcode

The information in this article applies to:

  • Microsoft FORTRAN for MS-DOS, version 5.1
  • Microsoft FORTRAN for OS/2, version 5.1

SYMPTOMS

Code compiled that contains a SELECT CASE block which compares a CHARACTER test expression against a case which is higher than 127 in the ASCII table may produce incorrect results.

CAUSE

When the compiler generates the code for the comparison of the CHARACTER test expression against the high ASCII constant it produces an incorrect comparison against a negative number which will always fail.

RESOLUTION

When comparing against ASCII values greater than 128, use integers for the comparison and convert the test expression from CHARACTER to INTEGER using the ICHAR intrinsic function.

STATUS

Microsoft has confirmed this to be a problem in FORTRAN version 5.1. This problem was corrected in FORTRAN PowerStation, version 1.0.

MORE INFORMATION

The following code can be used to reproduce the problem:

Sample Code #1

      CHARACTER A
      A = char(128)
      SELECT CASE (A)
        CASE (' ') ! insert ASCII 128 in the quotes using ALT+KEYPAD 128
            WRITE (*,*) 'High ASCII (128)'
        CASE DEFAULT
            WRITE (*,*) 'Failed Test'
      END SELECT
      END


The following code demostrates the solution:

Sample Code #2

      CHARACTER A
      A = char(128)
      SELECT CASE (Ichar(A))
        CASE (128)
            WRITE (*,*) 'High ASCII (128)'
        CASE DEFAULT
            WRITE (*,*) 'Failed Test'
      END SELECT
      END


Additional reference words: 5.10 buglist5.10 fixlist1.00
KBCategory: kbprg kbfixlist kbbuglist kbcode
KBSubCategory: FORTLngIss
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 16, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.