James said:
[..]
First, don't confuse scope with lifetime or linkage. A
declaration has scope, not a variable. [..]
A *name* has scope. A declaration is an _action_ that defines
the scope [of the name], [because it] happens in a scope, but
doesn't *have* it.
How right you are. In the end, a declaration is just a
directive to the compiler, telling it to do something. (There
are even some declarations which put the name in another scope;
the definition of a static class member, for example.)
A variable is an entity, a way to designate an object by means
of a name. Since a name and a variable are inseparable (a
variable cannot exist without a name), one can extend the
statement that a name has scope to mean that _a variable has
scope_. An *object* OTOH does not have a scope.
In other words, there are two categories of "objects", those
with names, and those without. Called, respectively, variables
and temporaries. But I don't think it's quite that simple in
C++, since scope is always limited to a single translation unit.
For various historical reasons, C++ distinguishes between scope
and linkage. Practically, it probably is acceptable to consider
external linkage as a "scope" which transcends translation unit
boundaries, provided we stick to the simple cases: the
declaration introduces the name into a more or less limited
scope in a single translation unit, even if the name is
"visible" in other translation units (external linkage). Thus,
for example, in:
void
f()
{
extern int i ;
}
The scope of `i' is limited to the function f, even though it
has external linkage, and an "extern int i ;" declaration in
another translation unit will associate the name i to the same
object.
The way I think of it, informally, is that scope defines the
visibility of a name, whereas linkage is concerned with the
binding of the name to the object (or function or reference).
Arguable, scope, linkage and lifetime are, or should be, more or
less orthogonal. But of course, they way they are specified is
very much linked in C++: scope affects the default lifetime,
even the type (as well as the scope) affects the default
linkage, and the same keyword will sometimes affect one,
sometimes another. If you tried to design something
intentionally to confuse beginners, you could hardly do a better
job of it.
I believe that's what you intended to express.
But didn't, at least not correctly

.