FORTRAN Reference Manual

Statements
FORTRAN Reference Manual528615-001
7-37
Equivalence With Length Differences
Equivalence With Length Differences
You can equivalence fields of different lengths as long as the EQUIVALENCE
statement does not violate the implicit alignment rules of these fields. The following
example equivalences the integer array N and the real array W and shows the
alignment of the two arrays:
DIMENSION n(9), w(6)
EQUIVALENCE (n(1), w(1))
Two elements of the array N occupy the same storage location as one element of the
array W.
Equivalencing Items in Common Blocks
Two entities in a common block cannot be equivalenced to each other, but a variable,
array, or array element in either a calling program or a subprogram can be made
equivalent to an item in a common block. In this case, an EQUIVALENCE statement
must not attempt to expand a common block by adding entities to storage ahead of the
first entity in the block. You can extend a common block beyond its current last storage
location. The following examples illustrate this restriction:
You cannot equivalence elements of two different common blocks.
Example
In the following example, the first five elements of the array RATE share the same
storage locations with the five-element array TOTAL:
DIMENSION rate(30), total(5)
EQUIVALENCE (rate(1), total(1))
Illegal Legal
COMMON xitem COMMON xitem
REAL price(5) REAL price(5)
EQUIVALENCE(xitem,price(5)) EQUIVALENCE(xitem,price(1))
DIMENSION n(9), w(6)
EQUIVALENCE (n(1), w(1))
n(1) n(7)n(4)n(3)n(2) n(8) n(9)n(6)n(5)
W(1) W(2) W(3) W(4) W(5) W(6)
VST0702.vsd