next up previous contents
Next: SAVE Statement Up: Program Units Previous: Host Association

Scope of Names

Consider the following example,

    SUBROUTINE sub1        ! scope sub1
     EXTERNAL sub4         ! scope sub1
     REAL A, B, C          ! scope sub1
      ...                  ! scope sub1
     CALL sub3(A)          ! scope sub1
     CALL sub4(A)          ! scope sub1
    CONTAINS
     SUBROUTINE sub3(D)   ! scope sub3
      REAL C, D           ! local C, D 
       ...                ! scope sub3
      C = A**3     ! A cant be changed
      D = D**3 + C ! D can be changed
      B = C  ! B from sub1; C from sub3 
       ...                ! scope sub3
     END SUBROUTINE sub3
    END SUBROUTINE sub1

    SUBROUTINE sub4(C)    ! scope sub4
     REAL B, C            ! scope sub4
       ...                ! scope sub4
      B = C               ! scope sub4
       ...                ! scope sub4
    END SUBROUTINE sub4
In sub3, A may not be changed but may be referenced.

For more information, click here gif

Now try this question gif


next up previous contents
Next: SAVE Statement Up: Program Units Previous: Host Association

Adam Marshall ©University of Liverpool, 1996
Fri Dec 6 18:56:08 GMT 1996
Not for commercial use.