Extending a Common Block with an EQUIVALENCE StatementLast reviewed: December 11, 1995Article ID: Q67229 |
The information in this article applies to:
SUMMARYAn EQUIVALENCE statement can be used to extend a common block size by EQUIVALENCing the last element of a common block with the first element of an array that is not in a common block. This is demonstrated in the code below. This article expands upon the information in the EQUIVALENCE statement section of the "Microsoft FORTRAN Reference" manual, which discusses extending common blocks found.
MORE INFORMATIONThe following code fragment shows a common block being extended from 4 bytes to 800 bytes in length. C ***** FORTRAN program fragment *****
REAL*4 VAR, A(200)
COMMON /TEST/ VAR
EQUIVALENCE (VAR, A(1))
In this fragment, the common block TEST is initially 4 bytes in
length. The equivalence statement specifies that VAR and A(1) will
share the same location in memory. Because all of A's elements are
contiguous in memory, the common block TEST is extended to be 200 x 4
or 800 bytes in length. This is shown graphically below:
|01|02|03|04|05|06|07|08|09|0A|0B|0C|0D|0E|0F|10| |------------------------------------------------ |....VAR....| |------------------------------------------------ |....A(1)...|....A(2)...|....A(3)...|....A(4)...| |------------------------------------------------ |<-- Beginning address of common block TESTThe guidelines listed below must be followed when using EQUIVALENCE to extend a common block's length:
REAL*4 VAR, A(200)
COMMON /TEST/ VAR
EQUIVALENCE (VAR, A(2))
Here VAR and A(2) will share the same memory location. Because A(1)
precedes A(2) in memory, it will also precede VAR, which is the
beginning of the common block. This is called extending a common
block forward and is shown graphically below:
|??|??|??|??|01|02|03|04|05|06|07|08|09|0A|0B|0C|0D|0E|0F|10
------------|------------------------------------------------
............|....VAR....|
------------|------------------------------------------------
|....A(1)...|....A(2)...|....A(3)...|....A(4)...|....A(5)...
------------|------------------------------------------------
............|<-- Beginning address of common block TEST
The following error is generated when the code listed above is
compiled:
F2320: A : EQUIVALENCE : extends common block TEST forward
C ***** FORTRAN program fragment *****
PROGRAM main
REAL*4 VAR, A(200)
COMMON /TEST/ VAR
EQUIVALENCE (VAR, A(1))
CALL sub()
.
.
END
SUBROUTINE sub ()
REAL*4 B
COMMON /TEST/ B(200)
.
.
RETURN
END
However, FORTRAN 5.0 will allow a NAMED common block to have
different sizes in subprogram units. In this situation, the compiler
generates the following warning:
F4329: TEST : COMMON : size changed
If the /4Ys compile option or $STRICT metacommand is used with
FORTRAN 5.0, or if the program is compiled with FORTRAN 4.x, the
error
F2323: TEST : COMMON : size changed
is generated when a NAMED common block's size is changed in a
subprogram.
Under Fortran PowerStation 4.0 using the /4Ys compile option or the
$STRICT metacommnad, a change in a subprogram common block's size
generates the following error message:
error FOR3750: byte count on numeric data type detected between * and 4 |
Additional reference words: kbinf 1.00 4.00 5.00 5.10
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |