FIX: Concatenated Output to Binary File Causes Machine Halt (86741)



The information in this article applies to:

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

This article was previously published under Q86741

SYMPTOMS

Applications repeatedly output concatenated strings to binary files may cause the machine to halt under MS-DOS or a Trap D protection violation under OS/2.

RESOLUTION

Assign the result of the string concatenation to a temporary variable to avoid the use of concatenation directly in WRITE statements to binary files. Or use commas to separate the output data rather than concatenation.

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 demonstrate the problem.

Sample Code #1

The following code reproduces the problem:

      character*100 aline

      aline = 'a'
      open(1,file='test.dat',form='binary')

      k = 100

      do i=1,10000
        print*, i
        write(1) aline(:k)//'b'
      end do

      end
				

Sample Code #2

The following code will correct the problem:

      character*100 aline
      character*101 bline

      aline = 'a'
      open(1,file='test.dat',form='binary')

      k = 100

      do i=1,10000
        print*, i
        bline = aline(:k)//'b'
        write(1) bline
      end do

      end
				

Sample Code #3

The following code will also correct the problem:

      character*100 aline

      aline = 'a'
      open(1,file='test.dat',form='binary')

      k = 100

      do i=1,10000
        print*, i
        write(1) aline(:k),'b'
      end do

      end
				

Modification Type:MajorLast Reviewed:10/23/2003
Keywords:kbfix KB86741