The SAVE attribute can be:
SUBROUTINE Barmy(arg1,arg2) INTEGER, SAVE :: NumInvocations = 0 NumInvocations = NumInvocations + 1
SUBROUTINE polo(x,y) IMPLICIT NONE INTEGER :: mint, neck_jumper SAVE REAL :: stick, car
In the above example mint, neck_jumper, stick and car all have the SAVE attribute.
Variables with the SAVE attribute are known static objects and have static storage class.
In fact, the SAVE attribute is given implicitly if an object, which is not a dummy argument or a PARAMETER, appears in an initialising declaration in a procedure, so
INTEGER, SAVE :: NumInvocations = 0
is equivalent to
INTEGER :: NumInvocations = 0
however, the former is clearer!
Clearly, the SAVE attribute has no meaning in the main program since when it is exited, the program has finished executing.
Objects appearing in COMMON blocks or DATA statements are automatically static.
Return to corresponding overview page