#1
static int a; #a
extern int a; #b // valid, 'a' still internal
#2
extern int b; #c
static int b; #d // invalid!
#3
const double pi1 = 3.14; #e
extern const double pi1; #f // valid and 'pi1' is internal
#4
extern const double pi2; #g
const double pi2 = 3.14; #h // valid but 'pi2' is now external
In #1, it's clear to me with accordance to 3.5: #a implies internal linkage.
And #b also implies internal linkage, because the name "a" is declared
static (by #a).
In #2, #c implies external linkage. But #d implies internal linkage because
the name "b" is declared static by #d. Thus -> invalid.
In #3, #e implies internal linkage, because it is const, and neither
declared explicit extern nor previously implied external linkage. And #f
should imply extern linkage and be an error, because it explicitly declares
the name extern, but the compilers keep it internal! Why so?.
In #4, #g implies external linkage because we explicitly declared extern.
And #h also implies external linkage because #g explicitly declared extern.
Thanks for all your insight!
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
For all that are interested, Charles Bailey and me had a discussion about
the semantics of #3 on Stackoverflow, and it turned out that there are
different ways to interpret section 3.5. See this link:
http://stackoverflow.com/questions/3538807/linkage-of-various-const-static-variables .