BUG: Nested Loops and FAR Arrays Produce Incorrect Results (70280)



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 Q70280

SYMPTOMS

Compiling a program that uses nested loops and FAR arrays causes one of the following run-time problems:
  1. Incorrect results -or-

  2. Protection violation -or-

  3. Run-time error R6001 - null pointer assignment -or-

  4. Run-time error F6207: WRITE(CON) - I edit descriptor expected for INTEGER
Note: A FAR array is defined as any array with a FAR attribute, any array greater than 32K compiled without the /Gt switch, or any array larger than the value set by the /Gt switch.

RESOLUTION

Possible solutions include

  1. Compile with /Od to turn loop optimization off (/Odct /Gs may also be used to retain some optimization) -or-

  2. Use the NEAR attribute on the array accessed within the inside loop.

STATUS

Microsoft has confirmed this to be a bug in the products listed above.

This is not an issue with FORTRAN PowerStation, since FAR is not a supported attribute.

MORE INFORMATION

The following sample can be used to demonstrate the problem.

Sample code

      PROGRAM NestedLoop
c
      INTEGER*4 Channel(10), IBuff[FAR](100)
      Count = 1
      DO 1 Loop1=1,10
        Channel(Loop1) = Loop1
        DO 2 Loop2=1,10
          IBuff(Count) = Loop1 + Loop2
          Count = Count + 1

   2    CONTINUE
   1  CONTINUE
c
c  line number 13
c
      END
				
During execution this program generates the R6001 error under MS-DOS or a protection violation under OS/2.

Substituting line 13 with the following statement will generate the F6207 error during execution under DOS or a protection violation under OS/2:
   WRITE(*,'(I8)') Channel(1)
				
Substituting line 13 with the following statement will generate incorrect results during execution under DOS or a protection violation under OS/2:
     WRITE(*,*) Channel, IBuff
				

Modification Type:MajorLast Reviewed:12/1/2003
Keywords:KB70280