# 4.1 AUTOMATIC and STATIC Statements

The AUTOMATIC and STATIC statements are used within a called subprogram to control the allocation of storage to variables and the initial value of variables.

The AUTOMATIC and STATIC statements take the following form:

    AUTOMATIC v [,v] . . .

    STATIC v [,v] . . .

v
  Is the name of a variable, array, or array declarator.

Rules and Behavior

The following table summarizes the differences between automatic and static variables upon entry to and exit from a subprogram.

Variable | Upon Entry | Upon Exit
--- | --- | ---
Automatic | Variable is undefined. It does not reflect changes caused by any previous execution of the subprogram. | The storage area allocated to the variable is deleted.
Static | Variable is defined with the value from the last execution of the subprogram.[1] | The current value of the variable is kept in the static storage area.
[1] If there has been no previous execution, the variable is undefined.

By default, all variables are static. To change the default from static to automatic, specify the compiler option RECURSIVE or AUTOMATIC.

To override the compiler option in effect for individual variables, specify the variables in AUTOMATIC or STATIC statements.

Note
  Variables that are data- initialized, and variables in COMMON, EQUIVALENCE, and SAVE statements are always static. This is regardless of whether you specify the RECURSIVE or AUTOMATIC compiler option or any previous AUTOMATIC specification.

Automatic variables can reduce memory use because only the variables currently being used are allocated to memory.

Automatic variables permit recursion. With recursion, a subprogram can call itself (directly or indirectly), and resulting values are available upon a subsequent call or return to the subprogram.

Examples

The following example shows a valid AUTOMATIC statement:

    INTEGER I, J(10)

    AUTOMATIC I, J, K(20)

The following example shows a valid STATIC statement:

    REAL C, D, E(30)

    STATIC C, D, E

For More Information:

- On subprograms, see Chapter 6.

- On names of compiler options used in this manual, see Section E.4.

Previous Page Next Page Table of Contents