This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [C++0x] nullptr


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]