sizeof a struc field

Norman Diamond diamond at csl.sony.co.jp
Thu Oct 19 11:51:27 AEST 1989


In article <277 at dsi.COM> dave at dsi.UUCP (Dave Rifkind) writes:

>>"Null pointer" is not a syntactic
>>concept--it's meaningful only at runtime.

In article <11316 at smoke.BRL.MIL> gwyn at brl.arpa (Doug Gwyn) writes:

>I said that dereferencing a null pointer CONSTANT was meaningless,
>and it is EXACTLY the kind of thing I want compilers to check for
>me at compile time.  There is no service being rendered by a compiler,
>when it is in a position to detect a usage error at compile time,
>silently proceeding to generate code that may blow up at run time.

(Dereferencing a null pointer NON-CONSTANT is just as meaningless.)
Sure, I'd be glad to have the compiler help diagnose errors at compile
time, under any condition where it knows appropriate information.

This entire argument concerns a null pointer constant inside a
_sizeof_ expression.  Mr. Gwyn, if your compiler is in a position to
detect a usage error at compile time, but it silently proceeds to
generate code TO EVALUATE SIZEOF that may blow up at run time, or if
it even generates code TO EVALUATE SIZEOF which will not blow up at
run time, I'd say you have a pretty bad compiler.  The entire reason
this argument exists is that _sizeof_ does not generate any code, it
does not dereference a null pointer, and it doesn't even stick a null
segment pointer into a segment register.  Until this posting of
Mr. Gwyn's, I thought both sides had valid points.
-- 
Norman Diamond, Sony Corp. (diamond%ws.sony.junet at uunet.uu.net seems to work)
  Should the preceding opinions be caught or     |  James Bond asked his
  killed, the sender will disavow all knowledge  |  ATT rep for a source
  of their activities or whereabouts.            |  licence to "kill".



More information about the Comp.lang.c mailing list