In article <11**********************@80g2000cwy.googlegroups. com>
coder <pl***********@gmail.comwrote:
>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.