HP Fortran Programmer's Reference (September 2007)

HP Fortran statements
EQUIVALENCE
Chapter 10354
The Fortran 90 standard imposes the following type restrictions on equivalenced objects:
If one of the objects in
equivalence-list
is of type default integer, default real, double
precision real, default complex, double complex, default logical, or numeric sequence type,
then all objects in
equivalence-list
must be one of these types.
HP Fortran relaxes this restriction and allows character and noncharacter items to be
equivalenced. Note, however, that use of this extension can impact portability.
If one of the objects in
equivalence-list
is of derived type that is not a numeric
sequence or character sequence type, then all objects in
equivalence-list
must be of the
same type.
If one of the objects in
equivalence-list
is of intrinsic type other than default integer,
default real, double precision real, default complex, double complex, default logical, or
default character, then all objects in
equivalence-list
must be of the same type with
the same kind type parameter value.
HP Fortran relaxes this restriction.
The EQUIVALENCE statement does not cause type conversion or imply mathematical
equivalence. If an array and a scalar share the same storage space through the EQUIVALENCE
statement, the array does not have the characteristics of a scalar and the scalar does not have
the characteristics of an array. They only share the same storage space.
Care should be taken when data types of different sizes share the same storage space, because
the EQUIVALENCE statement specifies that each data item in
equivalence-list
has the same
first storage unit. For example, if a 4-byte integer variable and a double-precision variable are
equivalenced, the integer variable shares the same space as the 4 most significant bytes of the
8-byte double-precision variable.
Proper alignment of data types is always enforced. The compiler will issue a diagnostic if
incorrect alignment is forced through an EQUIVALENCE statement. For data type alignment
rules, see “Intrinsic data types” on page 107.
The lengths of the equivalenced objects need not be the same.
Equivalencing character data
An EQUIVALENCE statement specifies that the storage sequences of character data items
whose names are specified in
equivalence-list
have the same first character storage unit.
This causes the association of the data items in
equivalence-list
and can cause association
of other data items as well. Consider the following example:
CHARACTER(LEN=4) :: a, b
CHARACTER(LEN=3) :: c(2)
EQUIVALENCE (a, c(1)), (b, c(2))