DOCERR: CHARACTER and REAL Can EQUIVALENCE on Odd Boundary

Last reviewed: July 18, 1995
Article ID: Q48868
The informaiton 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 reference words: 4.00 4.01 4.10 5.00 5.10
KBCategory: kbprg kbdocerr
KBSubcategory: FORTLngIss


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 18, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.