[PATCH] Fixes sentinel warnings on GCC4

Chris Shoemaker c.shoemaker at cox.net
Mon Dec 5 17:15:43 EST 2005


On Mon, Dec 05, 2005 at 04:38:40PM -0500, Derek Atkins wrote:
> If you were on IRC you'd have more information on this.
> 
> Yes, it is 64-bit only.  The problem is that on some versions of gcc4
> stddef.h #defined NULL as (int)0 which causes a compiler warning when
> passing that into a char*.

I'm no expert, and I don't actually know what gcc #defines NULL to,
but I don't think this is quite right.  I don't think this is a gcc
problem.  No compiler can infer the correct type for variadic
arguments.  In a variadic argument list, a compiler *must* interpret
an unqualified "0" (which is probably what NULL is) as integer type.
Our code is just wrong for any machine where the null pointer is not a
32 bit zero, even if it's some (imaginary) 32-bit machine.

> 
> The fix (which David is working on -- which you'd know if you were in
> IRC) is to #define GNC_NULL ((gpointer)0) and then use that instead of
> NULL in these places.

Hmm.  Seems a bit heavy-handed to me, but it would work.  I hope it
doesn't result in gratuitous use of GNC_NULL in the 99% of places
where NULL is fine.  

IMHO, it's better that programmers remain aware that the use of NULL
as a sentinel is "special".  IOW, *not* hiding this behavior gives a
better picture of what the code actually does, which tends to make for
better code and better programmers in the long run.  One problem I see
with GNC_NULL, is visibility.  If it's too visible, people use it
gratuitously; if it's not visible enough, people forget to use it when
they should; How to choose?  Better just to /understand/ what's going
on.

-chris



More information about the gnucash-devel mailing list