Static Scope

C uses a block structure, which permits blocks to be nested inside of each other. The scope of a declaration is the block that is most closely nested containing the declaration. Declaration D is located within Block B, but not within any block that is nested in B.

If declaration D of name x belongs to block B, then the scope of D is all of B, except for any blocks B' nested to any depth within B, in which x is redeclared. Here, x is redeclared in B' if some other declaration D' of the same name x belongs to B'.

A more mathematical approach is to focus on a use of a name x.

One important thing to note is that nested blocks that do not have conflicting declarations (declarations using the same name as an exterior block) are within scope of a declaration of a parent block.

Dynamic Scope

The use of the name x refers to the declaration of x in the most recently called, not-yet terminated, procedure with that declaration.

Dynamic scope resolution is essential for polymorphic procedures.

Last updated