EQUIVALENCE Statement (Nonexecutable) [ HP FORTRAN 77/iX Reference ] MPE/iX 5.0 Documentation
HP FORTRAN 77/iX Reference
EQUIVALENCE Statement (Nonexecutable)
The EQUIVALENCE statement associates variables so that they share the
same storage space.
Semantics
Function names, formal arguments, dynamic arrays, and record names must
not appear in an EQUIVALENCE statement. Each array or substring
subscript must be an integer constant expression.
The EQUIVALENCE statement conserves storage. For example, arrays that
are manipulated at different times in the same program can share the same
storage space through the EQUIVALENCE statement. Thus, the same storage
space is used for each array.
Equivalenced data items can be of different types. As an extension to
the ANSI 77 standard, character and noncharacter data items can share the
same storage space through the EQUIVALENCE statement.
The EQUIVALENCE statement does not cause type conversion or imply
mathematical equivalence. If an array and a simple variable share the
same storage space through the EQUIVALENCE statement, the array does not
have the characteristics of a simple variable and the simple variable
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 a list has the same first storage unit. For
example, if an INTEGER*4 variable and a REAL*8 variable share the same
storage space, the integer value occupies the same space as the leftmost
word of the two-word real value.
Equivalence of Character Variables
As an extension to the ANSI 77 standard, character and noncharacter data
items can share the same storage space.
Example Notes
---------------------------------------------------------------------------------------
EQUIVALENCE (a,b),(c(2),d,e) The variables a and b share the same
storage space; c(2), d, and e share the
same storage space.
Multi-Dimensioned Equivalence
As an extension to the ANSI 77 standard, it is possible to indicate the
element of an array with two or more dimensions by specifying its
position as if it were a single dimension array.
Example
BYTE message (4,10)
INTEGER name (10)
EQUIVALENCE (name, message(1))
Memory Storage Locations for Message and Name
----------------------------------------------------------------------------------------------
| | | |
| Array MESSAGE | Storage Space Byte Number | Array NAME |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| MESSAGE(1,1) | 1 through 4 | NAME(1) |
| MESSAGE(2,1) | | |
| MESSAGE(3,1) | | |
| MESSAGE(4,1) | | |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| MESSAGE(1,2) | 5 through 8 | NAME(2) |
| MESSAGE(2,2) | | |
| MESSAGE(3,2) | | |
| MESSAGE(4,2) | | |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| MESSAGE(1,3) | 9 through 12 | NAME(3) |
| MESSAGE(2,3) | | |
| MESSAGE(3,3) | | |
| MESSAGE(4,3) | | |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| MESSAGE(1,4) | 13 through 16 | NAME(4) |
| MESSAGE(2,4) | | |
| MESSAGE(3,4) | | |
| MESSAGE(4,4) | | |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| : | : | : |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| MESSAGE(1,10) | 37 through 40 | NAME(10) |
| MESSAGE(2,10) | | |
| MESSAGE(3,10) | | |
| MESSAGE(4,10) | | |
| | | |
----------------------------------------------------------------------------------------------
MPE/iX 5.0 Documentation