Lahey/Fujitsu Fortran

SAVE Statement

Description

The SAVE statement specifies that all data objects listed retain any previous association, allocation, definition, or value upon reentry of a subprogram.

Syntax

SAVE [[::] saved-entities]
Where:

saved-entities is a comma-separated list of:

object-name /common-block-name/

object-name is the name of a data object.

common-block-name is the name of a common block.

Remarks

Objects declared with the SAVE attribute in a subprogram are shared by all instances of the subprogram.

The SAVE attribute must not be specified for an object that is in a common block, a dummy argument, a procedure, a function result, or an automatic data object.

A SAVE statement without a saved-entities list specifies that all allowable objects in the scoping unit have the SAVE attribute.

If a common block name appears in a SAVE statement other than in the main program, it must be have the SAVE attribute in every scoping unit in which the name appears.

A SAVE statement in a main program has no effect.

Example

subroutine sub1() logical,save :: first_time=.true. ! save attribute integer :: saveval save :: saveval ! save statement if(first_time) then ! do initializations first_time=.false. saveval=1 end if saveval=saveval+1 ! value is preserved end subroutine