(ref.doc)clamage 290395

Next bs 010495 Prev: smeyers 300395 Up: Usenet

From: [email protected] (Steve Clamage)
Newsgroups: comp.lang.c++
Date: 29 Mar 1995 17:11:57 GMT

The phrase "function scope" is a technical term in C and C++ which in
its most narrow sense applies only to statement labels. The second use
probably should have been worded something like "the scope of the
identifier nrOfLines is the entire function."

Here is an example of the difference:

	foo()
	{
		int j;		// #1
		...
		int i;		// #2
	  l1:
		{
			int i;	// #3
			...
		}
		...
	}

The scope of 'j' (#1) is the entire function since there is no other j.
The scope of 'i' at #2 is not really the entire function, since there
is a "hole in the scope" at #3 where a new 'i' is declared. Further,
the scope of 'i'at #2 does not begin until the line #2 is reached.

The label l1 has function scope; it extends into inner scopes and cannot
be redefined. For example, you could not have another label l1 in this
function inside the block that contains #3. The scope of l1 includes
the beginning of the function, even before it is declared. You could
place a 'goto l1;' statement ahead of its declaration. By contrast,
you could not refer to 'i' until after its declaration.

automatically generated by info2www version 1.2.2.8