FIX: Bad Output with Element of Structure in CHAR Function

Last reviewed: September 11, 1997
Article ID: Q69002
5.00 5.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 5.0 and 5.1
  • Microsoft FORTRAN for OS/2, versions 5.0 and 5.1

SYMPTOMS

In FORTRAN 5.0 and 5.1, a program using the CHAR intrinsic function on a structure element within a WRITE or PRINT statement can produce erroneous output when executed under MS-DOS, or result in a protection violation when executed under OS/2.

RESOLUTION

To avoid these problems, remove the intrinsic function from the WRITE or PRINT statement by assigning the result of the CHAR intrinsic function to a temporary variable, and then use this variable in the output statement.

STATUS

Microsoft has confirmed this to be a problem in FORTRAN versions 5.0 and 5.1. This problem was corrected in FORTRAN PowerStation.

MORE INFORMATION

The following example reproduces the problem:

       structure /a/
         integer*2 i
       end structure

       record /a/ name
       name.i=97                   ! ASCII lowercase a
       write(*,*) char(name.i)
       end

  • When the above program is linked for MS-DOS, the resulting executable prints the wrong character or no character at all.

  • When it is linked for OS/2, the resulting executable generates a protection violation during runtime.

  • When it is compiled under MS-DOS with the patched version of F1.EXE (used to correct several problems with structures and NAMELIST statements) and linked for either DOS or OS/2, the executable generates the correct results.

  • When it is compiled under OS/2 with the patched version of F1.EXE, a protection violation is generated during compilation in the F2.EXE pass of the compiler.

    One possible solution is to assign the result of the CHAR intrinsic function to a temporary variable as illustrated by the following example:

           structure /a/
             integer*2 i
           end structure
    
           character c
           record /a/ name
           name.i=97              ! ASCII lowercase a
    
           c=char(name.i)
           write(*,*) c
           end
    

  • Additional reference words: 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.