standards/50889: NULL defined as 0 instead of (void *)0

Erik Trulsson ertr1013 at student.uu.se
Mon Apr 21 03:48:43 PDT 2003


On Mon, Apr 21, 2003 at 02:01:06AM -0600, M. Warner Losh wrote:
> I have a #define in my tree that I switch back and forth from time to
> time:
> 
> #if defined(_cplusplus) || !defined(_NULL_VOID)
> #define NULL 0L

Why not just plain 0?
I think either will work fine so it doesn't matter really matter much
but I am a bit curious.

> #else
> #define NULL (void *) 0

Won't work correctly.  You need to use ((void*)0) instead with the
extra parenthesis.  Otherwise expressions like 'sizeof NULL' will fail
to compile.

> #endif
> 
> and I add -D_NULL_VOID to build when I want to detect problems that
> (void *) 0 detects, then switch it back to 0 for the problems that
> that detects.
> 
> You can't win here.  I'd be inclined to leave things as the status quo.

I agree completely with that.


-- 
<Insert your favourite quote here.>
Erik Trulsson
ertr1013 at student.uu.se


More information about the freebsd-standards mailing list