XL Fortran for AIX 8.1

Language Reference



The EQUIVALENCE statement specifies that two or more objects in a scoping unit are to share the same storage.


                V                                          |

is a variable name, array element, or substring. Any subscript or substring expression must be an integer initialization expression.


equiv_object must not be a target, pointer, dummy argument, function name, pointee, entry name, result name, structure component, named constant, automatic data object, allocatable object, an object of a derived type containing an allocatable object as an ultimate component, object of nonsequence derived type, object of sequence derived type that contains a pointer in the structure, or a subobject of any of these.

Because all items named within a pair of parentheses have the same first storage unit, they become associated. This is called equivalence association. It may cause the association of other items as well.

You can specify default initialization for a storage unit that is storage associated. However, the objects or subobjects supplying the default initialization must be of the same type. They must also be of the same type parameters and supply the same value for the storage unit.

If you specify an array element in an EQUIVALENCE statement, the number of subscript quantities cannot exceed the number of dimensions in the array. If you specify a multidimensional array using an array element with a single subscript n, the n element in the array's storage sequence is specified. In all other cases, XL Fortran replaces any missing subscript with the lower bound of the corresponding dimension of the array. A nonzero-sized array without a subscript refers to the first element of the array.

If equiv_object is of derived type, it must be of a sequence derived type.

+-------------------------------IBM Extension--------------------------------+

You can equivalence an object of sequence derived type with any other object of sequence derived type or intrinsic data type provided that the object is allowed in an EQUIVALENCE statement.

In XL Fortran, associated items can be of any intrinsic type or of sequence derived type. If they are, the EQUIVALENCE statement does not cause type conversion.

+----------------------------End of IBM Extension----------------------------+

The lengths of associated items do not have to be equal.

Any zero-sized items are storage-associated with one another and with the first storage unit of any nonzero-sized sequences.

An EQUIVALENCE statement cannot associate the storage sequences of two different common blocks. It must not specify that the same storage unit is to occur more than once in a storage sequence. An EQUIVALENCE statement must not contradict itself or any previously established associations caused by an EQUIVALENCE statement.

You can cause names not in common blocks to share storage with a name in a common block using the EQUIVALENCE statement.

You can extend a common block by using an EQUIVALENCE statement, but only by adding beyond the last entry, not before the first entry. For example, if the variable that you associate to a variable in a common block, using the EQUIVALENCE statement, is an element of an array, the implicit association of the rest of the elements of the array can extend the size of the common block.


      REAL B(5)
      EQUIVALENCE (A,B(3))

Association of storage units:

          |      |      |      |      |      |      |      |      |
Array A:                |    A(1)     |    A(2)     |    A(3)     |
Array B:  | B(1) | B(2) | B(3) | B(4) | B(5) |

This example shows how association of two items can result in further association.

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

Association of storage units:

             |      |      |      |      |      |      |      |
Variable A:  |             A             |
Variable B:                       |             B             |
Array C:     |        C(1)        |        C(2)        |

Because XL Fortran associates both A and B with C, A and B become associated with each other, and they all have the automatic storage class.

      INTEGER(4)   G(2,-1:2,-3:2)
      REAL(4)      H(3,1:3,2:3)
      EQUIVALENCE  (G(2),H(1,1))   ! G(2) is G(2,-1,-3)
                                   ! H(1,1) is H(1,1,2)

Related Information

[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]