FIX: Bad Output with Element of Structure in CHAR Function

ID: Q69002


The information in this article applies to:
  • Microsoft FORTRAN for MS-DOS, versions 5.0, 5.1
  • Microsoft FORTRAN for OS/2, versions 5.0, 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 
  1. When the above program is linked for MS-DOS, the resulting executable prints the wrong character or no character at all.


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


  3. 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.


  4. 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 query words: 5.00 5.10

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


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