Pointer to extern char?

C

coder

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?
 
S

Sourcerer

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?


extern there should refer to goop, because 'char *const (__cdecl *)(int,long)'
is a return type and a return type cannot be extern. Makes no sense really.

--
"It is easy in the world to live after the world's oppinion; it easy in solitude
to live after our own; but the great man is he who in the midst of the crowd
keeps with perfect sweetness the independence of solitude."
Ralph Waldo Emerson, Self-reliance 1841
http://pinpoint.wordpress.com/
 
C

Chris Torek

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. :) )
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top