Microsoft KB Archive/48868

= DOCERR: CHARACTER and REAL Can EQUIVALENCE on Odd Boundary =

Article ID: 48868

Article Last Modified on 12/1/2003

-

APPLIES TO


 * Microsoft FORTRAN Compiler 4.0
 * Microsoft FORTRAN Compiler 4.01
 * Microsoft FORTRAN Compiler 4.1
 * Microsoft FORTRAN Compiler 5.0
 * Microsoft FORTRAN Compiler 5.1
 * Microsoft FORTRAN Compiler 4.1
 * Microsoft FORTRAN Compiler 5.0
 * Microsoft FORTRAN Compiler 5.1

-



This article was previously published under Q48868



SUMMARY
According to the sample code on Page 165 of the Microsoft FORTRAN &quot;Reference&quot; 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 &quot;Reference&quot; manual for versions 5.0 and 5.1 and on Page 211 of the Microsoft FORTRAN &quot;Language Reference&quot; 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: KB48868

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.