Re: using literal zero for NULL
- From: Hubert Figuiere <hfiguiere teaser fr>
- To: gtk-devel-list gnome org
- Subject: Re: using literal zero for NULL
- Date: Tue, 21 Mar 2006 11:37:09 -0500
Jon A. Cruz wrote:
Thanks. I am using c++ so I must use protptypes. I use -Wall also.
For C++, 0 is supposed to be preferred over NULL. For varargs, though,
the compiler might not know your intent. I've seen places that state
modern compliers treat NULL as exactly 0 (in which case
static_cast<void*>(0) should do the trick), however you should probably
check on a C++ newsgroup for details.
I did the following program in C++:
#include <stdio.h>
int main(int argc, char** argv)
{
printf("NULL: %d\n", sizeof(NULL));
printf("zero: %d\n", sizeof(0));
}
The output on amd64 is as follow:
NULL: 8
zero: 4
Note that in C, I get the exact same result.
So there is no reason to prefer 0 over NULL for pointers.
Hub
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]