Microsoft KB Archive/69981

From BetaArchive Wiki
< Microsoft KB Archive
Revision as of 18:58, 18 July 2020 by 3155ffGd (talk | contribs) (importing KB archive)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Array as Structure Element Generates Invalid Output PSS ID Number: Q69981 Article last modified on 10-16-1991

5.00 | 5.00

MS-DOS | OS/2

Summary:

In FORTRAN version 5.00, when accessing an array element of a structure in an I/O statement as if that array were a scalar variable, invalid results can be input or output. When the array is the first element of the structure, the input or output is correct.

If the array is of type CHARACTER, then incorrect results are always generated despite it’s position in the structure.

The F1.EXE patch, a replacement for the first pass of the compiler often used to correct structure element I/O problems, does not correct the output.

Assigning a temporary variable to the value of the array structure element and performing the I/O operations on the temporary variable will generate the correct results.

If accessing an array element of a structure from within a subroutine, query on the following words for more information:

F1001 and line and 1093

An internal compiler error or protection violation can occur during compile in this situation.

Microsoft has confirmed this to be a problem in Microsoft FORTRAN version 5.00 for MS-DOS and OS/2. This problem was corrected in FORTRAN version 5.10.

More Information:

The following code reproduces the problem with invalid output:

  structure /test/
    integer*4 i
    integer*4 j(2)
    integer*4 k(4)
  end structure

  record /test/ struc

  struc.i = 0
  struc.j = 1
  struc.k = 2

  print*,i                !   correct output generated:  0
  print*,struc.j          ! incorrect output generated:  0 1
  print*,struc.k          ! incorrect output generated:  0 1 1 2
  end

The pointer to the beginning of each array structure element is always set to the beginning of the structure and is not indexed correctly into the structure.

One possible solution is to use a temporary variable for the array in the I/O statement. The following code demonstrates this solution:

  structure /t/
      integer*4 i
      integer*4 j(2)
      integer*4 k(4)
  end structure

  integer   tempi
  integer*4 tempj(2)
  integer*4 tempk(4)
  record /t/ struc

  struc.i=0
  struc.j=1
  struc.k=2

  tempk=struc.i
  tempi=struc.j
  tempj=struc.k

  print*, tempi
  print*, tempj
  print*, tempk
  end
=================================================================

Copyright Microsoft Corporation 1991.