main
| Line | |
|---|
| 1 | c F77 Sec. 8.9: SAVE statement
|
|---|
| 2 | c The value of a SAVE variable is preserved across calls to a subroutine
|
|---|
| 3 | c or function.
|
|---|
| 4 | subroutine sub(t,b)
|
|---|
| 5 | integer a,b
|
|---|
| 6 | logical t
|
|---|
| 7 | save a
|
|---|
| 8 | if(t) then
|
|---|
| 9 | a = 2
|
|---|
| 10 | else
|
|---|
| 11 | a = a + 1
|
|---|
| 12 | end if
|
|---|
| 13 | c$ civl assert(a .eq. b)
|
|---|
| 14 | end subroutine
|
|---|
| 15 |
|
|---|
| 16 | subroutine sub2(t,b)
|
|---|
| 17 | integer a,b
|
|---|
| 18 | logical t
|
|---|
| 19 | c SAVE without a variable name preserves all variables in that subroutine
|
|---|
| 20 | save
|
|---|
| 21 | if(t) then
|
|---|
| 22 | a = 2
|
|---|
| 23 | else
|
|---|
| 24 | a = a + 1
|
|---|
| 25 | end if
|
|---|
| 26 | c$ civl assert(a .eq. b)
|
|---|
| 27 | end subroutine
|
|---|
| 28 |
|
|---|
| 29 | subroutine sub3(t,b)
|
|---|
| 30 | integer :: b
|
|---|
| 31 | logical :: t
|
|---|
| 32 | c Initialising a variable in the same line in which it is declared
|
|---|
| 33 | c implicitly activates the SAVE attribute for this variable.
|
|---|
| 34 | integer :: a = 2
|
|---|
| 35 | if(.not. t) then
|
|---|
| 36 | a = a + 1
|
|---|
| 37 | end if
|
|---|
| 38 | c$ civl assert(a .eq. b)
|
|---|
| 39 | end subroutine
|
|---|
| 40 |
|
|---|
| 41 | program p
|
|---|
| 42 | call sub(.true.,2)
|
|---|
| 43 | call sub(.false.,3)
|
|---|
| 44 | call sub(.false.,4)
|
|---|
| 45 | call sub2(.true.,2)
|
|---|
| 46 | call sub2(.false.,3)
|
|---|
| 47 | call sub2(.false.,4)
|
|---|
| 48 | call sub3(.true.,2)
|
|---|
| 49 | call sub3(.false.,3)
|
|---|
| 50 | call sub3(.false.,4)
|
|---|
| 51 | end program
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.