Re: Patch for definition of NULL
- From: Kaz Kylheku <kaz ashi footprints net>
- To: Raja R Harinath <harinath cs umn edu>
- Cc: Owen Taylor <otaylor redhat com>, <Mark Murnane Sun COM>, <gtk-devel-list gnome org>, <timj gtk org>
- Subject: Re: Patch for definition of NULL
- Date: Wed, 11 Jul 2001 22:17:40 -0700 (PDT)
On Wed, 11 Jul 2001, Raja R Harinath wrote:
> Owen Taylor <otaylor redhat com> writes:
> > Mark Murnane <Mark Murnane Sun COM> writes:
> >> When compiling glib with Sun's Forte compiler, we run across problems
> >> with the definition of NULL. On Solaris systems NULL is defined as
> >> either 0 or 0L, depending on whether or not you're compiling 64-bit
> >> binaries. I've put a conditional define in gmacros.h which only applied
> >> when Forte is being used. Does anyone have any objections if I commit
> >> this?
> >
> > I'm tending to thing that the right thing here is to simply include
> > stddef.h to get the corrent definition of NULL. Trying to match
> > all systems stddef.h with #ifdef's is a rats-nest I'd much
> > prefer not to enter.
A correct definition of NULL is simply 0. That works for C and C++.
In C, (void *) 0 is also a null pointer constant (and not a pointer
of type void *, note well), which is a good idea, because it
traps incorrect uses, where NULL appears in a non-pointer context.
I have no idea why Solaris switches between 0 and 0L; probably someone
clueless is maintaining the header. A zero-valued integral constant expression
is a null pointer constant. It doesn't matter if it's long, unsigned
or whatever. If they have a good reason, correct me.
So if I had to define NULL, I would write:
#ifdef __cplusplus
#define NULL 0
#else
#define NULL ((void *) 0)
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]