DOCERR: CHARACTER and REAL Can EQUIVALENCE on Odd Boundary (48868)



The information in this article applies to:

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

This article was previously published under Q48868

SUMMARY

According to the sample code on Page 165 of the Microsoft FORTRAN "Reference" manual for versions 5.0 and 5.1, when an application uses an EQUIVALENCE statement to match a character array to a REAL value such that the REAL value has an odd-numbered memory address, the compiler generates an error. This statement is incorrect; the sample code that demonstrates this situation compiles without error.

MORE INFORMATION

The following statement appears on Page 165 of the Microsoft FORTRAN "Reference" manual for versions 5.0 and 5.1 and on Page 211 of the Microsoft FORTRAN "Language Reference" manual for versions 4.01 and 4.1:

Microsoft FORTRAN permits character and noncharacter entities to be associated, but not in such a way that noncharacter entities start on an odd-byte boundary. If necessary, the compiler adjusts the storage location of the character entity so the noncharacter entity begins on an even byte. The following example causes a compile-time error:

      CHARACTER 1 char1(10)
      REAL reala, realb
      EQUIVALENCE (reala, char1(1))
      EQUIVALENCE (realb, char1(2))
					

An asterisk is missing from the character array declaration in the manual. The first line should read as follows:
      CHARACTER*1 char1(10)
				
This line of code has been corrected in the FORTRAN PowerStation Language Help.

The corrected code compiles correctly.

Sample Code

      CHARACTER*1 CHAR1(10)
      INTEGER*1 REALA, REALB
      EQUIVALENCE (REALA, CHAR1(1))
      EQUIVALENCE (REALB, CHAR1(2))
      REALA = 4
      REALB = 5
      WRITE(*,*) REALA, REALB
      WRITE(*,*) ICHAR(CHAR1(1)), ICHAR(CHAR1(2))
      END
				
Compiling the code above produces the following output:

4 5
4 5

The following information is available in the .LST style:
-----------------------------------------------------------------
Name                      Class   Type              Size   Offset

CHAR1 . . . . . . . . . . local   CHAR*1              10    0002
REALA . . . . . . . . . . local   INTEGER*1            1    0002
REALB . . . . . . . . . . local   INTEGER*1            1    0003
				

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