IBM Extension
Storage classes for variables
Note:
This section pertains only to storage for variables.
Named constants and their subobjects have a storage class of literal.
Fundamental storage classes
All variables are ultimately represented by one of five storage
classes:
- Automatic
- for variables in a procedure that will not be retained once the procedure
ends. Variables reside in the stack storage area.
- Static
- for variables that retain memory throughout the program. Variables reside
in the data storage area. Uninitialized variables reside in the bss storage
area.
- Common
- for common block variables. If a common block variable is initialized,
the whole block resides in the data storage area; otherwise, the whole block
resides in the bss storage area.
- Controlled Automatic
- for automatic objects. Variables reside in the stack storage area. XL Fortran allocates
storage on entry to the procedure and deallocates the storage when the procedure
completes.
- Controlled
- for allocatable objects. Variables reside in the heap storage area.
You must explicitly allocate and deallocate the storage.
Secondary storage classes
None of the following storage classes own their own storage,
but are associated with a fundamental storage class at run time.
- Pointee
- is dependent on the value of the corresponding integer pointer.
- Reference parameter
- is a dummy argument whose actual argument is passed to a procedure using
the default passing method or %REF.
- Value parameter
- is a dummy argument whose actual argument is passed by value to a procedure.
For details on passing methods, see %VAL and %REF.
Storage class assignment
Variable names are assigned storage classes in one of the
following ways:
- Explicitly:
- Dummy arguments have an explicit storage class of reference parameter
or value parameter. See %VAL and %REF for more details.
- Pointee variables have an explicit storage class of pointee.
- Variables for which the STATIC attribute is explicitly specified
have an explicit storage class of static.
- Variables for which the AUTOMATIC attribute is explicitly specified
have an explicit storage class of automatic.
- Variables that appear in a COMMON block have an explicit storage
class of common.
- Variables for which the SAVE attribute is explicitly specified
have an explicit storage class of static, unless they also appear in a COMMON statement, in which case their storage class is common.
- Variables that appear in a DATA statement or are initialized
in a type declaration statement have an explicit storage class of static,
unless they also appear in a COMMON statement, in which case their
storage class is common.
- Function result variables that are of type character or derived have the
explicit storage class of reference parameter.
- Function result variables that do not have the SAVE or STATIC attribute have an explicit storage class of automatic.
- Automatic objects have an explicit storage class of controlled automatic.
- Allocatable objects have an explicit storage class of controlled.
A variable that does not satisfy any of the above, but that is equivalenced
with a variable that has an explicit storage class, inherits that explicit
storage class.
A variable that does not satisfy any of the above, and
is not equivalenced with a variable that has an explicit storage class, has
an explicit storage class of static if:
- A SAVE statement with no list exists in the scoping unit or,
- The variable is declared in the specification part of a main program.
- Implicitly:
If a variable does not have an explicit storage
class, it can be assigned an implicit storage class as follows:
- Variables whose names begin with a letter, dollar sign or underscore that
appears in an IMPLICIT STATIC statement have a storage class of static.
- Variables whose names begin with a letter, dollar sign or underscore that
appears in an IMPLICIT AUTOMATIC statement have a storage class of
automatic.
In a given scoping unit, if a letter, dollar sign or underscore
has not been specified in an IMPLICIT STATIC or IMPLICIT AUTOMATIC statement, the implicit storage class is the same as that in the host.
Variables declared in the specification part of a module are associated
with the static storage class.
A variable that does not satisfy any
of the above but that is equivalenced with a variable that has an implicit
storage class, inherits that implicit storage class.
- Default:
All other variables have
the default storage class:
End of IBM Extension