[PATCH] Fixes sentinel warnings on GCC4

Karl Hegbloom hegbloom at pdx.edu
Tue Dec 6 11:43:21 EST 2005


On Mon, 2005-12-05 at 21:25 -0500, Chris Shoemaker wrote:
> If NULL is ((void*)0) you won't have any problem using NULL as a
> sentinel, but using that definition of NULL opens up the possibility
> of writing code that works with one implementation and not with
> another.  Specifically, you couldn't say "int *i = ((int *) NULL)" and
> be sure it would mean the same thing for every compiler.

Yes you could.  The whole point of the (void *) type is to represent a
generic pointer that can be assigned to any other pointer type _without_
a cast.  That's why it was invented.  In C, the variable holds the type,
not the value, so the (void *)0 automatically becomes an (int *) without
a cast.

A pointer to a char is the same size as a pointer to an int and is the
same size as a pointer to void.  The only difference is that when you
increment a char*, it clicks by one byte, and when you increment an
int*, it clicks by sizeof(int) bytes.  Since int *i, above, is a pointer
to int, it works as expected even though you initialize it with NULL.

-- 
Karl Hegbloom <hegbloom at pdx.edu>



More information about the gnucash-devel mailing list