Re: redeclaration of 'p' with no linkage



Mark McIntyre wrote:

On Mon, 20 Aug 2007 14:31:47 -0400, in comp.lang.c , Kenneth Brody
<kenbrody@xxxxxxxxxxx> wrote:

Mark McIntyre wrote:

Such objects have 'no linkage' and you can't have two of them in the
same scope. See 6.2.2 of the Standard.

Does that mean that this should be valid?

void foo(void)
{
static int *p;
int i;
extern int *p = &i;
}

My compiler doesn't allow it.

Interesting - I think that this ought to be allowed by 6.2.2p4,
though I'm happy to be corrected. Is this a C89 vs C99 thing?

"For an identifier declared with the storage-class specifier extern in
a scope in which a prior declaration of that identifier is visible, if
the prior declaration specifies internal or external linkage, the
linkage of the identifier at the later declaration is the same as the
linkage specified at the prior declaration. If no prior declaration is
visible, or if the prior declaration specifies no linkage, then the
identifier has external linkage."

I can't see it in C89.

6.1.2.2 Linkages of identifiers
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.
In the set of translation units and libraries that constitutes an
entire program, each instance of a particular identifier with
external linkage denotes the same object or function. Within one
translation unit, each instance of an identifier with internal
linkage denotes the same object or
function. Identifiers with no linkage denote unique entities.
If the declaration of a file scope identifier for an object
or a function contains the storageclass
specifier static, the identifier has internal linkage.
13
If the declaration of an identifier for an object or a function
contains the storage-class specifier extern, the identifier has
the same linkage as any visible declaration of the identifier
with file scope. If there is no visible declaration with file
scope, the identifier has external linkage.
If the declaration of an identifier for a function has no
storage-class specifier, its linkage is determined exactly
as if it were declared with the storage-class specifier extern.
If the declaration of an identifier for an object has file scope
and no storage-class specifier, its linkage is external.
The following identifiers have no linkage:
an identifier declared to be anything other than an object
or a function:
an identifier declared to be a function parameter;
a block scope identifier for an object declared without
the storage-class specifier extern.
If, within a translation unit, the same identifier appears
with both internal and external linkage, the behavior is undefined.

--
pete
.



Relevant Pages

  • Re: Shared Objects Libraries and Symbols...
    ... ~ 1 An identifier declared in different scopes or in the same scope more ... There are three kinds of linkage: ... each declaration of an identifier with internal ... ~ 4 For an identifier declared with the storage-class specifier extern ...
    (comp.os.linux.development.apps)
  • Re: Array definition guarantees
    ... linkage tells you where, ... identifier that is spelled sufficiently similarly. ... I think it is closer to say that scope tells you where the name ... The second glitch in this is the "extern" keyword. ...
    (comp.lang.c)
  • Re: Array definition guarantees
    ... linkage tells you where, ... identifier that is spelled sufficiently similarly. ... I think it is closer to say that scope tells you where the name ... The second glitch in this is the "extern" keyword. ...
    (comp.lang.c)
  • Re: redeclaration of p with no linkage
    ... Such objects have 'no linkage' and you can't have two of them in the ... "For an identifier declared with the storage-class specifier extern in ... the prior declaration specifies internal or external linkage, ... Identifiers declared within a block and without the extern keyword ...
    (comp.lang.c)
  • Re: Scope of specifier extern
    ... But none of them have scope; ... The keyword "extern" affects ... The "scope" concept answers the question "can I `see' that identifier ... The "linkage" concept ...
    (comp.lang.c)