On Aug 11, 2009, at 13:04, Greg Troxel wrote:
So it seems that NULL is expanding to (void *) 0, and "sizeof (void *)
0" is not legit.  AFAIK sizeof is specified to work on variables and
types, and NULL is neither a variable nor a type.
No, sizeof should work fine on expression values as well.  I'm not  
quite sure about the question of syntax here -- sizeof's operand may  
be "an expression or the parenthesized name of a type".  (So "sizeof  
var" is just a special case of the expression version, and doesn't  
require parentheses.)  But if the expression starts with a  
parenthesized type because it's a cast... looking at the grammar, I'd  
think it would be valid, but that would have implications for code  
such as "sizeof (unsigned long) + 3" ... is that a single expression  
(3UL) you're taking the size of, or a sum involving the size of a type?
Certainly "sizeof ((void *)0)", with the extra parens, works, and I  
think I've nearly always seen pointer versions of "NULL" using the  
enclosing parentheses, perhaps because of just this issue.  Assuming  
"sizeof (TYPE) EXPR" isn't valid, I'd call it a defect in your  
system's definition of NULL, though I wouldn't go so far as to call it  
non-compliant.  One could also argue that an expression provided to  
sizeof should always be parenthesized unless you know the syntax of it  
won't be altered by sticking "sizeof" in front, e.g., "sizeof(3+4)"  
instead of "sizeof 3+4".
However, they're testing for a POSIX 2008 requirement that C99 and  
POSIX 2004 implementations need not meet, namely that NULL be of type  
"void *" instead of any null pointer constant (e.g., "0").  I think  
requiring POSIX 2008 support for Guile and anything that builds on it  
seems like a bad idea.  I haven't looked at the libunistring code to  
see why it might be relevant, but it seems like a pretty gratuitous  
imposition to me.  The only benefit of it I can see is that a variadic  
function can then take NULL as an argument without casting to char*;  
is that worth refusing to support other systems?
Is NULL something else on Linux?
I'm not sure if it's GNU libc or GCC, but I'm getting "((void *)0)".

Ken


Reply via email to