5.17 SAVE Attribute and Statement

The SAVE attribute causes the values and definition of objects to be retained after execution of a RETURN or END statement in a subprogram.

The SAVE attribute can be specified in a type declaration statement or a SAVE statement, and takes one of the following forms:

Type Declaration Statement:

type, [att-ls,] SAVE [, att-ls] :: [object [, object]...]


SAVE [object [, object]...]

Is a data type specifier.

Is an optional list of attribute specifiers.

Is the name of an object, or the name of a common block enclosed in slashes (/common-block-name/).

Rules and Behavior

In Compaq Fortran, certain variables are given the SAVE attribute, or not, by default:

To enhance portability and avoid possible compiler warning messages, Compaq recommends that you use the SAVE statement to name variables whose values you want to preserve between subprogram invocations.

When a SAVE statement does not explicitly contain a list, all allowable items in the scoping unit are saved.

A SAVE statement cannot specify the following (their values cannot be saved):

Even though a common block can be included in a SAVE statement, individual variables within the common block can become undefined (or redefined) in another scoping unit.

If a common block is saved in any scoping unit of a program (other than the main program), it must be saved in every scoping unit in which the common block appears.

A SAVE statement has no effect in a main program.


The following example shows a type declaration statement specifying the SAVE attribute:

  REAL, SAVE :: X, Y

The following is an example of the SAVE statement:


For More Information:

Previous Page Next Page Table of Contents