Previous Topic Next topic Print topic


Defined Variables

A defined variable is one for which no storage is allocated. Instead, the variable shares the storage of a specified basis variable.

A defined variable is declared with the DEFINED attribute, which also specifies the basis variable. Any reference to the defined variable is a reference to all or part of the storage of the basis variable.

When the declaration of a variable includes the DEFINED attribute, that variable's description applies to the storage associated with the basis variable. For example:

DECLARE A(5) CHARACTER(1);
DECLARE X CHARACTER(5) DEFINED(A);

In this example, X is a defined character-string variable of length 5. X shares storage with, and is an alternate description of, the array A. Similarly, the following statement:

X = 'abcde';

assigns 'a' to A (1) , 'b' to A(2), and so on.

The extents of a defined variable can be integer valued expressions. They are evaluated upon block entry and stored in the stack frame just like the extents of automatic variables. Such an extent expression must not contain a reference to any non-static variable declared in the same block.

For additional information on defined variables, see the section Storage Sharing, which discusses the rules for giving alternate descriptions of storage.

Previous Topic Next topic Print topic