next up previous contents
Next: Lifetime of Variables Up: The Building Blocks of Previous: Modules   Contents

Scope of Variables

The scope of an entity is the part of the program where the entity is visible. The main program, a function or a procedure are scoping units; an entity declared inside a scoping unit is visible throughout the unit.

In particular, a variable declared in the main program or in a procedure has the body of the program/pocedure as its scope.

A variable is local (has local scope) if its scope is that of a scoping unit.

A variable whose scope is the entire program has global scope.

Some variables can be seen by multiple program units - by extension we will also talk about global scope. Global storage (global scope variables) can be implemented using modules or common blocks. This is discussed later in this chapter.

Adrian Sandu 2001-08-26