Topic: Possible defect: 'extern' reference?
Author: alfps@start.no (Alf P. Steinbach)
Date: Sat, 26 Nov 2005 14:47:12 CST Raw View
7.1.1/5 "The extern specifier can be applied only to the names of
objects and functions"
8.5.3/3 Mentions "where the extern specifier is explicitly used" in
normative text, and gives non-normative example "extern int& r2; //OK".
I have always thought a reference isn't an object: an object is a region
of storage, and a reference need not occupy any storage.
On the other hand an 'extern' reference seems to be able to solve real
problems, e.g. it seems it can solve a problem with the badly designed
WTL library from Microsoft where a global variable to be declared by the
client code is referred to by name from the WTL template code, and one
wants to use a derived type not yet known when including those headers.
Comeau Online 4.3.3, Visual C++ 7.1 and MinGW g++ 3.4.4 all accept
'extern' references:
extern int& r;
int x;
int& r = x;
int main() {}
I suggest fixing the immediate problem by changing the wording of
7.1.1/5 to
7.1.1/5 proposed resolution:
"The extern specifier can be applied only to the names of objects,
functions and references"
Then there's possibly also a need for clarifying whether a reference is
an object (as I see it, that it isn't).
--
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.jamesd.demon.co.uk/csc/faq.html ]
Author: Alberto Ganesh Barbati <AlbertoBarbati@libero.it>
Date: Sat, 26 Nov 2005 19:27:15 CST Raw View
Alf P. Steinbach wrote:
> 7.1.1/5 "The extern specifier can be applied only to the names of
> objects and functions"
Humoristically, in 8.3.2/1, a non-normative note states "a reference can
be thought of as a name of an object."
> 8.5.3/3 Mentions "where the extern specifier is explicitly used" in
> normative text, and gives non-normative example "extern int& r2; //OK".
8.3.2/4 explictly mentions the possibility that a reference declaration
can contain an extern specifier.
> I have always thought a reference isn't an object: an object is a region
> of storage, and a reference need not occupy any storage.
To be precise "It is unspecified whether or not a reference requires
storage" (8.3.2/3). That means a reference can require storage in some
cases and not require it in other cases.
> Then there's possibly also a need for clarifying whether a reference is
> an object (as I see it, that it isn't).
According to 1.8/1 "an object is a region of storage." So, as soon as a
reference is used in a way that requires storage to be allocated, it
*is* an object. Declaring the reference as extern is just one such use.
Just my opinion,
Ganesh
---
[ 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.jamesd.demon.co.uk/csc/faq.html ]