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

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