The EQUIVALENCE statement allows two or more entities in a program unit to share storage units, thus associating those entities. This statement allows the same information to be referenced by different names in the same program unit.
EQUIVALENCE (nlist) [,(nlist)] ... where nlist is a list of variable names, array element names, array names, and character substring names.
Method of Operation
The storage sequences of the entities in the list must have the same first storage unit. This requirement associates the entities in the list or other elements as well. The EQUIVALENCE statement only associates storage units and does not cause type conversion or imply mathematical equivalence. Thus, if a variable and an array are equivalenced, the variable does not assume array properties and vice versa.
Character entities can be associated by equivalence only with other character entities. Specify the character entities, character variables, character array names, character array element names, or character substring names. Association is made between the first storage units occupied by the entities appearing in the equivalence list of an EQUIVALENCE statement. This statement can associate entities of other character elements as well. The lengths of the equivalenced character entities are not required to be equal.
Variables and arrays can be associated with entities in common storage to lengthen the common block. However, association through the use of the EQUIVALENCE statement must not cause common storage to be lengthened by adding storage units before the first storage unit in the common block.
Rules for Use
The following shows a valid EQUIVALENCE statement using the arrays a and b:EQUIVALENCE (a(1,1), b(4,2))
The following example achieves the same effect:EQUIVALENCE (a(1), b(4))
The lower-bound values in the array declaration are always assumed for missing subscripts (in the above example, 1 through 3 for array a and 2 through 4 for array b).
The two statements below are represented in storage as shown in Figure below.
Figure: Storage Representation of an EQUIVALENCE Statement
CHARACTER ABT*6, BYT(2)*4, CDT*3
The two statements below cause the logical representation in storage shown in Figure below.
Figure: Logical Representation of an EQUIVALENCE Statement
The following statements are invalid because they specify non-consecutive storage positions for consecutive storage units.
Note that a double-precision variable occupies two consecutive numeric storage units in a storage sequence.
All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.