<div class="gmail_quote">On Wed, Nov 9, 2011 at 14:49, Lisandro Dalcin <span dir="ltr"><<a href="mailto:dalcinl@gmail.com">dalcinl@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div id=":2z4">In my 64 bits Fedora 15, sizeof(NULL) is 8 with g++ and icpc. But I'm<br>
not sure all compilers/platforms will work like that. In those cases,<br>
you could conditionally define to 0 or 0L depending of sizeof(void*)</div></blockquote></div><br><div>The C++ standard not specify that, when interpreted without conversion to a specific pointer type (e.g. variadic function) that it have the correct size. GCC works around this by adding __null.</div>
<div><br></div><div><div>/* A null pointer constant.  */</div><div><br></div><div>#if defined (_STDDEF_H) || defined (__need_NULL)</div><div>#undef NULL             /* in case <stdio.h> has defined it. */</div><div>
#ifdef __GNUG__</div><div>#define NULL __null</div><div>#else   /* G++ */</div><div>#ifndef __cplusplus</div><div>#define NULL ((void *)0)</div><div>#else   /* C++ */</div><div>#define NULL 0</div><div>#endif  /* C++ */</div>
<div>#endif  /* G++ */</div><div>#endif  /* NULL not defined and <stddef.h> or need NULL.  */</div><div>#undef  __need_NULL</div></div><div><br></div><div><br></div><div>If this header is used by a non-GCC compiler, it will use the definition 0 instead of __null. (That is supposed to be supported.)</div>
<div><br></div><div>We could test for this behavior of NULL, but it feels like an incomplete solution to me.</div>