4.7.2 Making Substrings Equivalent

When you make one character substring equivalent to another character substring, the EQUIVALENCE statement also sets equivalences between the other corresponding characters in the character entities; for example:

CHARACTER NAME*16, ID*9
EQUIVALENCE (NAME(10:13), ID(2:5))

As a result of these statements, the character variables NAME and ID share space as illustrated in Figure 4-1.

The following statement also aligns the arrays as shown in Figure 4-1:

EQUIVALENCE (NAME(9:9), ID(1:1))

If the character substring references are array elements, the EQUIVALENCE statement sets equivalences between the other corresponding characters in the complete arrays.

Figure 4-1 Equivalence of Substrings

Character elements of arrays can overlap at any character position; for example:

CHARACTER FIELDS(100)*4, STAR(5)*5
EQUIVALENCE (FIELDS(1)(2:4),  STAR(2)(3:5))

As a result of these statements, the character arrays FIELDS and STAR share storage space as shown in Figure 4-2.

Figure 4-2 Equivalence of Character Arrays

The EQUIVALENCE statement cannot assign the same storage location to two or more substrings that start at different character positions in the same character variable or character array. The EQUIVALENCE statement also cannot assign memory locations in a way that is inconsistent with the normal linear storage of character variables and arrays.


Previous Page Next Page Table of Contents