[Development] 0 vs. NULL

Pocheptsov Timur timur.pocheptsov at theqtcompany.com
Fri Oct 9 15:58:37 CEST 2015


In C++ you can do:

int * p = NULL;
double * d = NULL;

if NULL was (void *)0 - you'd have a compilation error in C++, since there is no such implicit conversion.

And yes, void * in C++ can be indeed considered generic, because you can do this:

int * p = ...
void * pv = p;

________________________________________
From: development-bounces+timur.pocheptsov=theqtcompany.com at qt-project.org <development-bounces+timur.pocheptsov=theqtcompany.com at qt-project.org> on behalf of René J. V. Bertin <rjvbertin at gmail.com>
Sent: Friday, October 09, 2015 3:51 PM
To: development at qt-project.org
Subject: Re: [Development] 0 vs. NULL

Thiago Macieira wrote:

I missed this message.


> "The macro NULL is an implementation-defined C++ null pointer constant in this
> International Standard(180)"
>
> And the note reads
>
> "180)Possible definitions include 0 and 0L, but not (void*)0."

Does the note say why or is it just an arbitrary decision? 0 and 0L do not look
like pointer constants for someone coming from C, whereas (void*)0 does. I
thought void* was the generic pointer even in C++ (at least the "more
traditional" implementations)?

R

_______________________________________________
Development mailing list
Development at qt-project.org
http://lists.qt-project.org/mailman/listinfo/development



More information about the Development mailing list