Kaz Kylheku <
k...@kylheku.com> writes:
> Consider:
>
> "An identifier declared in different scopes or in the same scope
> more than once can be made to refer to the same object or
> function by a process called linkage. There are three kinds of
> linkage: external, internal, and none." [C99, 6.2.2]
>
> How can "none" be a kind of linkage? [snip elaboration]
Clearly an identifier having no linkage means there is no process
by which it can be made to refer to the same object or function as
those referred to by the same identifier in other declarations.
Since there is no means by which this declaration's identifier can
be made to refer to an entity associated with an identifier in
any other declaration, it seems appropriate to say there is "no
linkage" for this occurrence of the identifier.
> "If an identifier has no linkage, there shall be no more than one
> declaration of the identifier (in a declarator or type specifier)
> with the same scope and in the same name space, except for tags
> as specified in 6.7.2.3." [C99, 6.7]
>
> So, "no linkage" is in fact a kind of linkage, just with a poor
> name.
No, because the question of whether there is more than one
declaration of a given identifer (in the same scope, etc) does
not have to do with what entity it refers to but only what its
name is. You are confusing "linkage" with "spelling" (plus what
scopes and name spaces the various uses appear in, which again
do not depend on what objects or functions are referred to).
> Consider the situation
>
> { int x; int x; }
>
> which violates a constraint. But the diagnosis of the constraint
> violation requires x to be deemed as having linkage.
No, it doesn't.
> The diagnosis logically depends on:
>
> 1. An identifier is being declared more than once in the same
> scope.
This statement is correct.
> 2. That identifier refers to the same object or function.
This statement is incorrect. Any declaration of struct members
never refers to any object or function, and determining whether
the identifiers in the two declarations are the same does not
depend on what objects/functions they might refer to but only
how they are spelled.
> and these requires the "process called linkage".
>
> The process of looking up x in one declaration to see whether it
> was already mentioned by another declaration is linkage!
No, it's symbol table association, or some other term the
Standard doesn't define. The notion of 'linkage' is just about
whether two declarations of an identifier might refer to the
same object or function, which doesn't enter into the question
being addressed here.
> x has linkage, and it's just not allowed. So "no linkage" doesn't
> mean "lack of linkage" but something like "disallowed linkage".
>
> But the exception for struct and union tags shows that in fact
> some forms of "no linkage" are allowed. So the process by which
> two struct declarations arefer to the same struct, is evidently
> linkage of type "none". W00T?
Tags for struct and union (and enums) also have no linkage,
because they never can refer to the same object or function.
This obviously is true, because tags never refer to an
object or function under any circumstances.
I don't see any reason to prefer this approach to what the
Standard takes currently. There is still a need to associate
multiple declarations to a single object or function, you're
just not calling that association "linkage". Using the word
"linkage" for both external linkage and internal linkage seems
appropriate, as it is common for both to occur during a link
step rather than a compile step. Also, I think it might be
significantly harder under this approach to express all the
different combinations of declarations that C currently allows;
you might writing out your idea in Standardese to see what is
needed here -- it's not as easy as you might think.
Incidentally, your rule for when identifers may be redeclared
needs augmenting for C11's new provision for typedef names.