Re: Patch for definition of NULL



Kaz Kylheku wrote:

> 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

That defiinition is the one already used by glib, but because __cplusplus isn't
defined, we get the latter definition.  For whatever reason, Forte doesn't like
this.  Hence the patch.

The reason for using 0L is that in a 64-bit environment, you need a 64-bit NULL.
You just end up with problems otherwise.  I don't know why its not defined as 0L
all the time, but Solaris has a long history, and I haven't been around long
enough to fathom all of the reasoning behind it :-)

But I prefer the idea of #include <stddef.h>.  I'm not sure where to put it aside
from glib.h itself.  As far as I can tell, glibconfig.h isn't included by any
files until gmacros has been included, so we'll still end up with a defintion of
NULL that Forte is unhappy with.

Thanks,

Mark

------------------------------
Mark Murnane
Desktop, Applications and Middleware
Sun Microsystems Ireland
------------------------------





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]