HP Fortran Programmer's Reference (September 2007)

HP Fortran statements
EQUIVALENCE
Chapter 10 355
As a result of this EQUIVALENCE statement, the fourth character in a, the first character in b,
and the first character in c(2) share the same storage.
Strings of the same or different lengths can be equivalenced to start on the first element, and
you can use substring notation to specify other associations, as in the following:
CHARACTER (10) :: s1, s2
EQUIVALENCE (s1(2:2), s2(3:3)
Substring subscripts must be integer initialization expressions, and the substring length
must be nonzero.
Equivalencing arrays
To determine equivalence between arrays with different dimensions, HP Fortran views all
elements of an array in linear sequence. Each array is stored as if it were a one-dimensional
array. Array elements are stored in ascending sequential, column-major order; for information
about how arrays are laid out in memory, see “Array fundamentals” on page 57.
Array elements can be equivalenced with elements of a different array or with scalars. No
equivalence occurs outside the bounds of any of the equivalenced arrays.
If equivalenced arrays are not of the same type, they may not line up element by element.
If an array name appears without subscripts in an EQUIVALENCE statement, it has the same
effect as specifying an array name with the subscript of its first element.
It is illegal to equivalence different elements of the same array to the same storage area. For
example, the following is illegal:
INTEGER :: a(2), b
EQUIVALENCE (a(1), b), (a(2), b)
Likewise, it is illegal to use the EQUIVALENCE statement to force consecutive array elements to
be noncontiguous, as in the following example:
REAL :: a(2), r(3)
EQUIVALENCE (a(1), r(1)), (a(2), r(3))
Array subscripts must be integer initialization expressions.
Equivalence in common blocks
An EQUIVALENCE statement must not cause two common blocks to be associated. However, you
can use the EQUIVALENCE statement to place objects in common by equivalencing them to
objects already in common. If one element of an array is equivalenced to an object in common,
the whole array is placed in common with equivalence maintained for storage units preceding
and following the data element in common. The common block is always extended when it is
necessary to fit an array that shares storage space in the common block. It may be extended
after the last entry, but not before the first.