Copyright (c) 1994 J. Adams, W. Brainerd, J. Martin, and B. Smith. All rights reserved. This file may not be copied without permission of the authors.
A variable with the SAVE attribute retains its value and definition, association, and allocation status on exit from a procedure. All variables accessible to a main program are saved implicitly. An entire common block may be saved in order to maintain the integrity of the storage when none of the procedures using the common block are active. Similarly, saving a variable in a module preserves its value when no procedure using the module is active.
MODULE FLOWERS REAL, SAVE, ALLOCATABLE :: FOLIAGE(:) ! FOLIAGE is real type and . . . ! has the SAVE attribute. END MODULE FLOWERS SAVE A, B, TEMP, /BLOCKXY/ ! A common block, BLOCKXY ! has the SAVE attribute. RECURSIVE SUBROUTINE ATLATL (X, Y) INTEGER :: COUNT = 0 ! COUNT is saved . . . ! automatically. COUNT = COUNT + 1 . . . CALL ATLATL (X, Y) . . . END SUBROUTINE ATLATL SUBROUTINE DAISY SAVE ! This saves everything. . . . END SUBROUTINE DAISY
Tip: Even though many implementations of Fortran 77 saved all variables and named common blocks, a standard-conforming program may not rely on this. Modern systems are more complex and more attention should be paid to variables that must retain their value in Fortran 90. Unless the SAVE attribute has been declared, a variable might not be saved. For the sake of portability, the SAVE attribute should always be declared for variables that need to retain their value.
Data Initialization
Recursion
ISO 1539 : 1991, Fortran Standard, 5.1.2.5, 5.2.4
Fortran 90 Handbook, 5.5.1, 5.6.4, 12.1.3
Programmer's Guide to Fortran 90, 3.5, 10.2.2
A type declaration statement with the SAVE attribute is:
type , SAVE
[ ,
attribute-list ] ::
entity-list
A SAVE statement is:
SAVE
[ [ ::
] saved-entity-list ]
A saved entity is one of:
data-object-name
/
common-block-name /