Source-Changes-D archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: CVS commit: src/sys/kern

On Jan 31, 2012, at 3:53 PM, Alexander Nasonov wrote:
> David Laight wrote:
>> I don't believe there is a problem using m[0], just m[non-constant-expr].
> Practically speaking, m[0] is not a problem but the standard says
> ... to the structure member (designated by member-designator), ...
>                     ^^^^^^
>> OTOH 'sizeof (s *)0->m[0]' might be deemed invalid (because it has
>> an inferred dereference of NULL.
> Oh yes. I can change it to:
> extern void *foo(void);
> and then sizeof(((s *)foo())->m[0]) but NULL should work too.
> So, if we reached a consensus on this, where should I add the macro?

There's no NULL dereference, so it is fine (completely standards conforming).  
The sizeof operator is a compile time construct that evaluates its argument for 
its type only, so no dereference is happening, so any value for the pointer is 
OK.  In the absence of a local variable, 0 is just as valid as anything else.


Home | Main Index | Thread Index | Old Index