Re: Const declaration in header files
* James Kanze:
On May 26, 1:13 pm, "Alf P. Steinbach" <al...@start.no> wrote:
There is however a non-normative note at the end of ?8.3.4/1
that attempts to explain this. Presumably what it's meant to
explain is that the /intent/ of that paragraph is that
cv-qualification of array elements transfer to the array
object itself.
A very feeble attempt, IMHO. But perhaps sufficient if it were
normative.
Anyway, it explicitly says "internal linkage".
Where?
<q>
Note: an "array of N cv-qualifier-seq T" has cv-qualified type;
</q>
which I (now I see, explained below, probably incorrectly, although opinions
differ) read as an attempted explanation that the element CV-qualification is
transferred to the array object itself, and continues, emhpasis added
<q>
such an array has *internal linkage* unless explicitly declared 'extern'
(7.1.5.1) and must be initialized as specified in 8.5.
</q>
Of course if it were taken literally it would raise the issue of auto variables
with internal linkage.
In the C++0x draft, at least my old version, the latter quoted part is removed,
and instead there is a reference to ?3.9.3 about CV-qualification, where it's
made clear that my interpretation above is not the one to be adopted in C++0x,
Current and C++0x
?3.9.3/2
"Any cv-qualifiers applied to an array type affect the array
element type, not the array type (8.3.4)."
The change in ?8.3.4/1 wording, removal of that part about internal linkage,
follows core language Defect Report #112 discussion,
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#112
which touches on the linkage issue but does not resolve it or really discuss it
(the only concern is that "volatile" should not result in internal linkage).
Hm.
[snip]
Anyhow, I think it's all vague enough for me to raise an issue
with the committee. I'm not sure, but judging from the behavior
of the compilers I've tested, I think that there is more or less
a consensus that the const-ness of the array elements *should*
cause internal linkage (as if the array itself were const); it's
just a question of making this clear in the wording of the
standard.
I agree, good idea.
Cheers,
- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?