Array Reference Assignment

<array reference assignment>

──<array reference variable>── := ─┬─<array designator>─┬──────────────┤
                                   └─<null value>───────┘

An array reference assignment associates a variable, called an array reference variable, with an array or a portion of an array. The array reference variable can then be used to reference the array or array portion.

An array reference assignment generates a copy descriptor of an array or array row.

Typical uses of an array reference assignment include the following:

  • To perform more efficiently arithmetic operations on multidimensional arrays (for example, by extracting a particular row to avoid repeated indexing to the same row)

  • For concurrent, but different, uses of the same array (for example, for storing values of type REAL into an array that is originally declared as Boolean)

Array Reference Variable

<array reference variable>

──<array reference identifier>─────────────────────────────────────────┤

The array reference variable cannot be global to the array designator.

If the array reference variable is declared as DIRECT, then only an array designator for a direct array can be assigned to it. However, a nondirect array reference variable can be assigned an array designator for either a direct or a nondirect array.

The dimensionality of the array reference variable and the array designator must be the same. If both are multidimensional, then the array classes must be compatible. INTEGER, REAL, and BOOLEAN types are compatible with each other. Other array classes are compatible only with themselves. If the array reference identifier and the array designator are both one-dimensional, then they can have any array class.

The size of each dimension of a multidimensional array reference variable is the same as the size of the corresponding dimension of the array designator. The size of a one-dimensional array reference variable is determined by the size and element width of the array designator and the element width for the array class with which the array reference variable was declared. Let Sa and Wa be the size and element width, respectively, of the array designator, and let Wr be the element width for the array reference variable. The size of the array reference variable, Sr, is then the following:

Sr := (Sa * Wa) DIV Wr

Because of the truncation implicit in the DIV operation, Sr * Wr might be less than Sa * Wa. In this case, indexing the array reference variable by S+LB, where LB is the lower bound in the ARRAY REFERENCE declaration, does not cause an invalid index fault. Pointer operations using the array reference variable can access the entire area of memory allocated to the original array to which the array designator ultimately refers; the memory area may hold more than Sr elements of width Wr.

Array Designator

<array designator>

──<array name>─┬─────────────────────┬─────────────────────────────────┤
               └─<subarray selector>─┘

<subarray selector>

                               ┌◄─ , ─┐
── [ ─┬──────────────────────┬─┴─ * ──┴─ ] ────────────────────────────┤
      │ ┌◄─────────────────┐ │
      └─┴─<subscript>── , ─┴─┘

The array designator indicates the array or array portion to be associated with the array reference variable. Following an array reference assignment, the array reference variable becomes a referred array, describing the same data as the array designator, which can itself be an original array or another referred array.

A subarray selector selects part of an array by specifying subscripts for high-order dimensions and leaving others unspecified. The unspecified dimensions are indicated by an asterisk (*). The dimensionality of the subarray is the number of asterisks in the subarray selector.

The total number of subscripts and asterisks in a subarray selector must equal the dimensionality of the array identifier to which the subarray selector is suffixed. In the case of no subscripts, the number of asterisks equals that dimensionality, and the subarray is the whole array. In all other cases, the subarray selector specifies a subarray of reduced dimensionality.

For example, assume you are using the following declarations:

ARRAY A[0:9,1:40,0:99];
INTEGER I,J; % (ASSUME 0 <= I <= 9 AND 1 <= J <= 40)

For these declarations, the following applies:

A and A[*,*,*]

Denote the entire three-dimensional array.

A[I,*,*]

Denotes one of the 10 two-dimensional arrays that constitute A.

A[I,J,*]

Denotes one of the 40 one-dimensional arrays (array rows) that constitute A[I,*,*], and one of the 400 one-dimensional arrays that constitute A.

If the array designator is an uninitialized array reference variable, the array reference assignment causes the target array reference variable to become uninitialized.

Examples of Array Reference Assignments

BOOLARRAY := REELARRAY
EBCDICARAY := INPUTARAY[*]
SUBARRAY :=BIGARRAY[N,*,*]
ARAYROW := MULTIDIMARAY[I,J,K,*]