Rational Developer for System z
Enterprise PL/I for z/OS, Version 3.8, Language Reference Manual

Automatic storage and attribute

Automatic variables are allocated on entry to the block in which they are declared. They can be reallocated many times during the execution of a program. You control their allocation by your design of the block structure.

Read syntax diagramSkip visual syntax diagram>>-AUTOMATIC---------------------------------------------------><
 

Abbreviation: AUTO

AUTOMATIC is the default. Automatic variables are always internal.

In the following example, each time procedure B is invoked, the variables X and Y are allocated storage. When B terminates, the storage is released, and the values X and Y contain are lost.

A: proc;

·
·
·
call B; B: proc; declare X,Y auto;
·
·
·
end B;
·
·
·
call B;

The storage that is freed is available for allocation to other variables. Thus, whenever a block (procedure or begin) is active, storage is allocated for all variables declared automatic within that block. Whenever a block is inactive, no storage is allocated for the automatic variables in that block. Only one allocation of a particular automatic variable can exist, except for those procedures that are called recursively or by more than one program.

Extents for automatic variables can be specified as expressions. This means that you can allocate a specific amount of storage when you need it. In the following example, the character string STR has a length defined by the value of the variable N when procedure B is invoked.

A: proc;
declare N fixed bin;

·
·
·
B: proc; declare STR char(N);

If the declare statements are located in the same block, PL/I requires that the variable N be initialized either to a restricted expression or to an initialized static variable. In the following example, the length allocated is correct for Str1, but not for Str2. PL/I does not resolve this type of declaration dependency.

dcl N fixed bin (15) init(10),
M fixed bin (15) init(N),
Str1 char(N),
Str2 char(M);


Terms of use | Feedback

This information center is powered by Eclipse technology. (http://www.eclipse.org)