next up previous contents
Next: The USE Renames Facility Up: Modules Previous: Modules - Procedure Encapsulation

 

Encapsulation - Stack example

We can also encapsulate the stack program,

    MODULE stack
     IMPLICIT NONE
     INTEGER, PARAMETER :: stack_size = 100
     INTEGER, SAVE :: store(stack_size), pos=0
    CONTAINS
     SUBROUTINE push(i)
      INTEGER, INTENT(IN) :: i
       ...
     END SUBROUTINE push
     SUBROUTINE pop(i)
      INTEGER, INTENT(OUT) :: i
       ...
     END SUBROUTINE pop
    END MODULE stack

Any program unit that includes the line:

    USE stack
    CALL push(2); CALL push(6); ..
    CALL pop(i); ....
can access pop and push therefore use the 100 element global integer stack.

For more information, click here gif


next up previous contents
Next: The USE Renames Facility Up: Modules Previous: Modules - Procedure Encapsulation

©University of Liverpool, 1997
Wed May 28 23:37:18 BST 1997
Not for commercial use.