next up previous contents
Next: Scope of Variables Up: The Building Blocks of Previous: Comments   Contents

Modules

Modules are special program units, delimited by the following syntax:

module  $\langle$module_name$\rangle$
$\qquad \vdots$ 
end module  $\langle$module_name$\rangle$

A module contains only declarations of different entities; it can contain no executable statements. Other program units (functions, subroutines, main program or even other modules) can attach the module, and by doing so they can ``see'' (have access to) the entities declared in the module.

Therefore, the functionality of a module is to declare objects and to make them available to other program units. In this regard, they are different from procedures (which are supposed to perform some computations, some I/O, etc).

We can attach a module to a program unit by inserting

use $\langle$module_name$\rangle$
as the first statement in the program unit (right after the header, and right before any declaration).

Jargon: when a program unit USEs a module, it has access to the (public) objects declared in the module; we say that the module entities are visible within that program unit by use-association.

Note that, in particular, modules can be attached to other modules, which in their turn can be attached to other modules etc. In this situation we have to be careful not to create a circular definition, which is of course prohibited. An example of a circular, hence mistaken definition, is: module 2 uses module 1, module 3 use module 2 and module 1 uses module 3.

What we said here is not the whole story with modules: it suffices for now, but we will study more in the future.


next up previous contents
Next: Scope of Variables Up: The Building Blocks of Previous: Comments   Contents
Adrian Sandu 2001-08-26