FORTRAN 77 Language Reference

EQUIVALENCE

The EQUIVALENCE statement specifies that two or more variables or arrays in a program unit share the same memory.

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

Parameter 

Description 

nlist

List of variable names, array element names, array names, and character substring names separated by commas  

Description

An EQUIVALENCE statement stipulates that the storage sequence of the entities whose names appear in the list nlist must have the same first memory location.

An EQUIVALENCE statement can cause association of entities other than specified in the nlist.

An array name, if present, refers to the first element of the array.

If an array element name appears in an EQUIVALENCE statement, the number of subscripts can be less than or equal to the number of dimensions specified in the array declarator for the array name.

Restrictions

In nlist, dummy arguments and functions are not permitted.

Subscripts of array elements must be integer constants greater than the lower bound and less than or equal to the upper bound.

EQUIVALENCE can associate automatic variables only with other automatic variables or undefined storage classes. These classes must be ones which are not in any of the COMMON, STATIC, SAVE, DATA, or dummy arguments.

An EQUIVALENCE statement can associate an element of type character with a noncharacter element. @

An EQUIVALENCE statement cannot specify that the same storage unit is to occur more than once in a storage sequence. For example, the following statement is not allowed:


       DIMENSION A (2) 
       EQUIVALENCE (A(1),B), (A(2),B) 

An EQUIVALENCE statement cannot specify that consecutive storage units are to be nonconsecutive. For example, the following statement is not allowed:


       REAL A (2) 
       DOUBLE PRECISION D (2) 
       EQUIVALENCE (A(1), D(1)), (A(2), D(2)) 

When COMMON statements and EQUIVALENCE statements are used together, several additional rules can apply. For such rules, refer to the notes on the COMMON statement.

Example


       CHARACTER A*4, B*4, C(2)*3 
       EQUIVALENCE (A,C(1)),(B,C(2))

The association of A, B, and C can be graphically illustrated as follows. The first seven character positions are arranged in memory as follows:

 

         01 

        02 

         03 

         04 

        05 

        06 

        07 

       A(1) 

       A(2) 

        A(3) 

       A(4) 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

       B(1) 

        B(2) 

       B(3) 

       B(4) 

 

 

 

 

 

 

 

 

     C(1)(1) 

     C(1)(2) 

     C(1)(3) 

     C(2)(1) 

     C(2)(2) 

     C(2)(3)