FIX: Bad Output with Element of Structure in CHAR Function (69002)



The information in this article applies to:

  • Microsoft FORTRAN Compiler for MS-DOS 5.0
  • Microsoft FORTRAN Compiler for MS-DOS 5.1
  • Microsoft FORTRAN compiler for OS/2 5.0
  • Microsoft FORTRAN compiler for OS/2 5.1

This article was previously published under Q69002

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
				

Modification Type:MajorLast Reviewed:12/1/2003
Keywords:kbfix KB69002