DOCERR: CHARACTER and REAL Can EQUIVALENCE on Odd Boundary

ID: Q48868


The information in this article applies to:
  • Microsoft FORTRAN for MS-DOS, versions 4.0, 4.01, 4.1, 5.0, 5.1
  • Microsoft FORTRAN for OS/2, versions 4.1, 5.0, 5.1


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 

Additional query words: 4.00 nofps 4.01 4.10 5.00 5.10

Keywords :
Version : :4.0,4.01,4.1,5.0,5.1
Platform :
Issue type :


Last Reviewed: November 3, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.