next up previous contents
Next: Implicit SAVE Attribute Up: Program Units Previous: Example of Scoping Issues

 

SAVE Statement

  Local objects are:

so they do not retain their values between two separate procedure calls.

If a local variable has the SAVE attribute then it will retain its value and allocation status between calls, for example, consider,

   SUBROUTINE sub1(A)
    IMPLICIT NONE
    REAL :: A
    REAL, SAVE :: r
    REAL, ALLOCATABLE, DIMENSION(:,:), SAVE :: X
     :
    IF (.NOT.ALLOCATED(X)) ALLOCATE(X(20,20))

the value that r holds on exit from the procedure will persist and will be available the next time the procedure is entered. Likewise, the array X will remain allocated and its value preserved between calls; both these objects are called saved-objects or static objects and belong to the corresponding static storage class.

Clearly, the SAVE attribute has no meaning in the main program since when it is exited, the program has finished executing. Dummy arguments or objects which depend on dummy arguments (for example, automatic objects, see Section 5.1.2) cannot have the SAVE attribute. This is because the dummy arguments will be different on each invocation of the procedure.


next up previous contents
Next: Implicit SAVE Attribute Up: Program Units Previous: Example of Scoping Issues

Adam Marshall ©University of Liverpool, 1996
Fri Dec 6 15:03:35 GMT 1996
Not for commercial use.