TITLE: internal linkage and arrays (Newsgroups: comp.lang.c++.moderated, 7 May 99) MEYERS: Scott Meyers >>> In fact, the only way I can think of to give a char array >>> internal linkage is to put it in an unnamed namespace or >>> make it file static. HENRIKSSON: Dag Henriksson >> Strictly speaking, to put it in an unnamed namespace doesn't >> give the char array internal linkage. But it can not be seen >> from any other translation unit, so the effect is the same. CLAMAGE: Steve Clamage >It's not quite the same: > >static const char* s1 = "hello"; >namespace { > const char* s2 = "hello"; >} >template class C { ... }; > >C c1; // error: s1 must have external linkage >C c2; // ok > --------------------------------------------------------- NARAN: Siemel Naran >>>> extern const char s[]="hello"; // the 'extern' is necessary MEYERS: Scott Meyers >>> I'd expect it to have external linkage here, too: >>> Is there a special linkage rule for char arrays? BARFURTH: Joerg Barfurth >> In a way. The way arrays are special is about cv-qualification. >> See the note at the end of [8.3.4]/p.1. CLAMAGE: Steve Clamage >The C++ committee is currently discussing that note (prompted >by the postings in this thread). > >Here's the last part of that paragraph, including an example, >and the note in question: >------------------------------------------------------ >Any type of the form "cv-qualifier-seq array of N T" is adjusted to >"array of N cv-qualifier-seq T," and similarly for "array of unknown >bound of T."[Example: > typedef int A[5], AA[2][3]; > typedef const A CA; // type is "array of 5 const int" > typedef const AA CAA; // type is "array of 2 array of 3 const int" >-end example] >[Note: an "array of N cv-qualifier-seq T" has cv-qualified type; such >an array has internal linkage unless explicitly declared extern >(7.1.5.1) and must be initialized as specified in 8.5. ] >------------------------------------------------------ > >The note appears to contradict the sentence and example that >immediately precede it, although some have claimed there is >no contradiction. > >The note does contradict section 3.9.3 paragraph 2 which says >explicity that cv-qualifiers do not apply to the array type, >but only to the element type. Since a note is non-normative, >this paragraph must take precedence. > >Finally, if the note is correct, the declaration > volatile char s[]="hello"; >would have internal linkage. That is clearly wrong, so at a >minimum the note must be modified to say "const-qualified" >instead of cv-qualified. > >But I think the whole note is wrong and should be deleted. >If you want an array to have internal linkage, you can declare >it static. I don't see any reason to make a special rule. > >If a special rule is needed, putting it in a note doesn't work. >A note or example can only be used clarify or expand on the >normative (official, non-note, non-example) text. No text other >than the note currently says that > const char s[]="hello"; >has internal linkage. > >For the reasons I have listed, I think that const arrays have >external linkage unless declared static.