Re: Linkage of namespace scope reference
* johnchx2@yahoo.com:
Alf P. Steinbach wrote:
One would expect, and I did originally expect, that when initialization
is required, internal linkage is implied, but this special case breaks
that expectation -- for no good reason that I can see.
I don't think I understand why "one would expect" any relationship
between the linkage of a name and whether an explicit initializer is
required where the name is defined.
It's an expectation that the language does not have (too many!)
completely arbitrary requirements. For internal linkage there's no need
to just declare a reference or constant, and the possibility of just
declaring is a bit dangerous, hence the requirement of initialization
makes sense in that context. But the point of external linkage is to
have one definition and many just declarations, so the requirement
doesn't make sense in that context: for external linkage it's arbitrary.
Another point of view is that it's the external linkage of "T& r=o;"
that's arbitrary.
Anyway, it's arbitrary, against expectation: I doubt that anybody
frequenting this group has ever written "T& r=o;" to define a reference
that's used in other translation units.
[snip]
The extern keyword doesn't change whether a definition requires an
initializer;
True, because a reference definition always requires an initializer.
it only changes whether a declaration without an
initializer is also an (ill-formed) definition.
Typo? Sorry, I can't parse that.
--
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?
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]