Next: Linkage in C Up: Accessing items in Previous: Accessing items in

Scope and extent

We will informally use the word ``item'' to mean a variable or function. For most of what follows it might help to focus on a simple variable while you come to grips with it. In fact it applies in just the same way to function names.

Definition The scope of a definition is that part of the program where the definition is accessible.

In the simple case, this means all of the block in which it was defined, except that it goes out of scope if the same name is redefined in an inner block.

Example

int x;

/* x is in scope here */
   {
   int x;  /* A second variable with the same name */
   /* First x is out of scope here */
   /* Second x is in scope here */
   }
/* First x is in scope here */
/* Second x is out of scope here */
}

Definition The extent of a definition is that part of the program for which the definition exists.

In the above example, the first x extends from the point at which it is defined to the end of the program. The second x extends from the point at which it is defined to the end of the inner block. These two definitions are general, not C terminology.



Next: Linkage in C Up: Accessing items in Previous: Accessing items in


maspjw@
Tue Sep 27 15:29:34 BST 1994