the entity it denotes can be referred to by names from other scopes in the same translation unit.
For this to make sense, you have to understand the difference between the entity and the name.
In your main function, you are creating a new entity and giving it the name a
. The name does not refer to the same entity called a
that is in namespace A. It's a different entity not only because it has different linkage, but also because it is in a different namespace.
Local variables have no linkage by default, and so they always specify a new entity. For example
static int a = 5; // a new entity with name `a` that has internal linkage.
int main()
{
int a; // This is a new entity local to function main with no linkage.
// It isn't initialized, so you have undefined behavior if you try to
// access it.
}
In this case, you have two entities, both named a
, but they refer to different entities because they are in different scopes with different linkages.
The situation the standard is referring to is like this:
static int a = 5; // A new entity with the name `a` that has internal linkage.
void f()
{
extern int a; // This is a new declaration for the same entity called `a` in
// the global scope.
}
Now you only have one entity, but you still have two names in two different scopes. Those two names are referring to that same single entity.
This is a very tricky point. Because the declaration inside f()
has extern
, you are saying that you want f's a
to refer to an entity that is defined elsewhere. However, since there is already a declaration for a
at global scope that is declared static
, it makes the a
have internal linkage instead of external linkage.
Note that there isn't much practical value for having two names for the same entity with internal linkage since you can always just use the first name instead.