Re: Pointer to extern char?



In article <1165687643.736968.301280@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
coder <plcoderNOSPAM@xxxxxxxxx> wrote:
While reading the page on "Reading C Declarations"
<http://www.ericgiguere.com/articles/reading-c-declarations.html>
(recommended by Mr. Heathfield at
<http://www.cpax.org.uk/prg/portable/c/resources.php>), I came across
the following declaration:

extern char *const (*goop( char *b ))( int, long );

which is explained as:

declare goop as function returning pointer to function returning const
pointer to extern char

How can there be a pointer to extern char? Doesn't extern here mean
that the function has external linkage?

Yes, the explanation is just wrong.

"extern" is one of the four (well, five, sort-of) storage-class
specifiers (the complete list is: auto, extern, register, static,
typedef; typedef is an sc-specifier just for syntax purposes).
The presence of an sc-specifier modifies identifiers, not types:

static int a, *b, c(foo);

makes "a", "b", and "c" all static.

The actual modification performed by an sc-specifier is contextual,
so it can be difficult to describe. For instance, "static" affects
linkage when a declaration occurs at file scope, but affects
storage-duration when a declaration occurs at block scope. The
"extern" keyword usually gives identifiers external linkage, but
not always.

In the example above, "goop" has external linkage (just as you have
said) unless an earlier declaration is in scope that already gave
it internal linkage. That is, given:

static int foo(void);
extern int foo(void);

both declarations specify internal linkage -- the "extern" here
means "static" (!). Delete the first line, however, and the second
line suddenly means "external" (!). Omitting "extern" gives the
identifier external linkage, so:

static int foo(void);
int foo(void);

is an error (although no diagnostic is required) -- adding the
"extern" fixes the code so that both declarations of foo() give it
internal linkage.

(Nobody ever said C was consistent. :-) )
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
.



Relevant Pages

  • Re: extern needed or not?
    ... Functions have external linkage by default. ... Well I read in K&R that when extern is omitted it's a temporary declaration. ... static int int_value = 100; ... and also removes the "tentativity" of the ...
    (comp.lang.c)
  • Re: extern
    ... >> 6.2.2p4 fully defines the meaning of the extern keyword, ... >> declaration with the extern keyword does not reverse the original ... Declared extern usually implies external linkage, ...
    (comp.lang.c)
  • Re: Suggestions for declarations.
    ... Spiros Bousbouras wrote: ... Just declare them without using extern. ... but if I remove the early extern declaration and ... (uppercase 'D' is 'external linkage, ...
    (comp.lang.c)
  • Re: Suggestions for declarations.
    ... Just declare them without using extern. ... but if I remove the early extern declaration and ... (uppercase 'D' is 'external linkage, ... You have to mark BOTH as static obviously ...
    (comp.lang.c)
  • Re: extern
    ... >> extern. ... For objects it is a "tentative declaration" NOT ... Mark McIntyre was taking about objects. ... The tentative definition in question has external linkage. ...
    (comp.lang.c)