# 4.7 EQUIVALENCE Statement

The EQUIVALENCE statement partially or totally associates two or more entities in the same program unit with the same storage location. It takes the following form:

    EQUIVALENCE (nlist) [,(nlist)] . . .

nlist
  Is a list of variables, arrays, array elements, or character substring references, separated by commas. The list must contain at least two of these entities.

  Each expression in a subscript or a substring reference must be an integer constant expression.

Rules and Behavior

Dummy arguments, records, and record fields cannot be specified in EQUIVALENCE statements.

The EQUIVALENCE statement causes all of the entities in one parenthesized list to be allocated storage beginning at the same storage location.

Entities having different data types can be associated because multiple components of one data type can share storage with a single component of a higher-ranked data type. For example, if you make an integer variable equivalent to a complex variable, the integer variable shares storage with the real part of the complex variable.

Examples

In the first example, the EQUIVALENCE statement makes the four elements of the integer array IARR occupy the same storage as that of the double-precision variable DVAR.

    DOUBLE PRECISION DVAR

    INTEGER*2 IARR(4)

    EQUIVALENCE (DVAR, IARR(1))

In the next example, the EQUIVALENCE statement makes the first character of the character variables KEY and STAR share the same storage location. The character variable STAR is equivalent to the substring KEY(1:10).

    CHARACTER KEY*16, STAR*10

    EQUIVALENCE (KEY, STAR)

Previous Page Next Page Table of Contents