[petsc-dev] Problem with PETSC_NULL and variadic functions

Jed Brown jedbrown at mcs.anl.gov
Wed Nov 9 15:03:45 CST 2011


On Wed, Nov 9, 2011 at 14:49, Lisandro Dalcin <dalcinl at gmail.com> wrote:

> In my 64 bits Fedora 15, sizeof(NULL) is 8 with g++ and icpc. But I'm
> not sure all compilers/platforms will work like that. In those cases,
> you could conditionally define to 0 or 0L depending of sizeof(void*)
>

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.

/* A null pointer constant.  */

#if defined (_STDDEF_H) || defined (__need_NULL)
#undef NULL             /* in case <stdio.h> has defined it. */
#ifdef __GNUG__
#define NULL __null
#else   /* G++ */
#ifndef __cplusplus
#define NULL ((void *)0)
#else   /* C++ */
#define NULL 0
#endif  /* C++ */
#endif  /* G++ */
#endif  /* NULL not defined and <stddef.h> or need NULL.  */
#undef  __need_NULL


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.)

We could test for this behavior of NULL, but it feels like an incomplete
solution to me.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20111109/6b28ab9e/attachment.html>


More information about the petsc-dev mailing list