This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [C++0x] nullptr
- From: Christopher Jefferson <chris at bubblescope dot net>
- To: Ed Smith-Rowland <3dw4rd at verizon dot net>
- Cc: Magnus Fromreide <magfr at lysator dot liu dot se>, Jason Merrill <jason at redhat dot com>, gcc-patches at gcc dot gnu dot org, libstdc++ at gcc dot gnu dot org
- Date: Mon, 3 May 2010 08:04:30 +0100
- Subject: Re: [C++0x] nullptr
- References: <1268546192.2028.32.camel@sara.home> <4BA46E77.6080507@redhat.com> <1269813166.2249.8.camel@sara.home> <4BB12B74.80703@redhat.com> <4BDD0915.2020301@redhat.com> <1272842221.2000.26.camel@sara.home> <4BDE597C.30609@verizon.net>
On 3 May 2010, at 06:05, Ed Smith-Rowland wrote:
> Greetings,
>
> I tried to do nullptr and I'm gratified that some of what I tried you did too ;-).
> It was a learning experience as I had never touched the front end before.
>
> Anyway, my question is this:
> In gcc we
> #define NULL __null.
> OTOH the committee thought about and ultimately rejected
> #define NULL nullptr
>
> Can/should we go ahead and do this since we sort of did it already?
> If we don't want to do this would it be a good idea to have a flag
> -fNULL=nullptr o somesuch?
>
Changing NULL to nullptr does break some code. In particular, consider the following, not unreasonable, code:
void f(int*);
void f(double*);
This code will fail to compile if given NULL, regardless of if the NULL is 0 or nullptr.
To "fix" this for NULL=0, we have to add:
void f(int i) { assert(i==0); }, which is a little dodgy looking.
To fix this for NULL=nullptr, we add the nicer looking:
void f(typeof(nullptr)) { ... }
However note that without some very messy looking code, it isn't possible to fix this in such a way that it is:
a) Valid C++03 code (for people who want to stay on C++03)
b) accepts NULL=nullptr
Chris