C scope overlapping

Viewed 347

The C standard states (emphasis mine):

If an identifier designates two different entities in the same name space, the scopes might overlap. [...]

(section 6.2.1.4 from http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf)

When can an identifier refer to two different entities but their scopes do not overlap?

Or, put differently, why is there the word "might" in the quote?

3 Answers

Read it as “The scopes might overlap, if an identifier designates two different entities in the same name space.” That is, the sentence is saying the scopes might overlap, and it is explaining the condition for which that occurs. English is unfortunately imprecise. This sentence is not meant to express the logic statement that if an identifier designates two entities in the same name space, there exist programs in which they overlap and there exist programs in which they do not. It expresses the fact that scopes might overlap and the fact that this occurs when an identifier designates two different entities in the same name space.

These scopes for name overlap:

int f(void) {
  int name = 4;
  {
     int name = 6;
  }
}

These ones do not overlap:

int f(void) {
  {
     int name = 4;
  }
  {
     int name = 6;
  }
}

I think the word might refer to possibilty of the general case rather than probability of hapening (that means is allowed to happen and when it happens there would be an overlap). And the following lines indactes that by telling what happens in this case (the inner scope would be a strict subscope of the outer one and in this scope we will be using the intety defined inside this inner scope

Related