ALLOCATE statement for controlled variables
The ALLOCATE statement allocates
storage for controlled variables, independent of procedure block
boundaries. Controlled parameters can also be allocated. The bounds
of controlled arrays, the lengths of controlled strings, and the
size of controlled areas, as well as their initial values, can be
specified in the ALLOCATE statement.
 >>-ALLOCATE----------------------------------------------------->
.-,-------------------------------------------------.
V |
>----+-------+--controlled-variable--+---------------+-+--;----->
'-level-' '-| attribute |-'
>--| attribute: |----------------------------------------------->
>--+-dimension-------------------------------------------+-----><
+-CHARACTER(length)-----------------------------------+
+-BIT(length)-----------------------------------------+
+-GRAPHIC(length)-------------------------------------+
+-WIDECHAR(length)------------------------------------+
+-AREA(size)------------------------------------------+
| .-,----. |
| V | |
+-INITIAL(---item-+-)---------------------------------+
'-INITIAL CALL--entry-reference--+------------------+-'
| .-,--------. |
| V | |
'-(---argument-+-)-'
|
Abbreviation: ALLOC
- level
- Indicates a level number. If no level number is specified,
the controlled-variable named must be a level-1 variable.
- controlled-variable
- Specifies a controlled variable or an element of a controlled
major structure. A structure element, other than the major structure,
can appear only if the relative structuring of the entire major
structure containing the element appears as it is in the DECLARE
statement for that structure. In this case, dimension attributes
must be specified for all names that are declared with the dimension
attribute.
Both controlled and based variables can be allocated in the same
statement. For the syntax of based variables, refer to ALLOCATE statement for based variables.
Bounds for arrays, lengths of strings, and sizes of areas (extents)
are evaluated at the execution of an ALLOCATE statement:
- Either the ALLOCATE statement or a DECLARE or DEFAULT statement
must specify any necessary dimension, size, or length attributes
(extents) for a variable. Any expression taken from a DECLARE statement
is evaluated at the point of allocation using the conditions enabled
at the ALLOCATE statement. However, names in the expression refer
to those variables whose scope includes the DECLARE or DEFAULT statement.
- If a bound, length, or size is explicitly specified in an ALLOCATE
statement, it overrides that given in the DECLARE statement for
that variable.
- If a bound, length, or size is specified by an asterisk in an
ALLOCATE statement, that extent is taken from the current generation.
If no generation of the variable exists, the extent is undefined
and the program is in error.
- If, in either an ALLOCATE or a DECLARE statement, bounds, lengths,
or sizes are specified by expressions that contain references to
the variable being allocated, the expressions are evaluated using
the value of the most recent generation of the variable. For example:
declare X(N) fixed bin ctl;
N = 20;
allocate X;
allocate X(X(1));
In the first allocation of X, the upper bound is specified by the declare statement and N = 20;. In the second allocation, the upper bound is specified by
the value of the first element of the first generation of X.
The dimension attribute must specify the same number of dimensions
as declared. The dimension attribute can appear with any of the
other attributes and must be the first attribute specified. For
example:
declare X(M) char(N) controlled;
M = 20;
N = 5;
allocate X(25) char(6);
The BIT, CHARACTER, GRAPHIC, WIDECHAR and AREA attributes can
appear only for variables having the same attributes, respectively.
Initial values are assigned to a variable upon allocation, if
the variable has an INITIAL attribute in either the DECLARE or ALLOCATE
statement. Expressions or the CALL option in the INITIAL attribute
are evaluated at the point of allocation, using the conditions enabled
at the ALLOCATE statement. However, the names are interpreted in
the environment of the declaration. If an INITIAL attribute appears
in both DECLARE and ALLOCATE statements, the INITIAL attribute in
the ALLOCATE statement is used. If initialization involves reference
to the variable being allocated, the reference is to the new generation
of the variable. For more information on initialization, refer to INITIAL attribute.
Any evaluations performed at the time the ALLOCATE statement
is executed (for example, evaluation of expressions in an INITIAL
attribute) must not be interdependent.
If storage for the controlled variable is not available, the
STORAGE condition is raised.
|
This information center is powered by Eclipse technology. (http://www.eclipse.org)