sizeof a struc field

Dr. T. Andrews tanner at cdis-1.uucp
Sat Oct 21 00:53:39 AEST 1989


) 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.

I would suggest that, since sizeof() generates an integral constant,
that any compiler which generated code which blew up for
	sizeof(((type *)0)->member)		/* cited construct */
has a basic flaw.

So far, we have heard that dereferencing a null pointer is garbage
(but we aren't dereferencing one), and that null pointer CONSTANTS
shouldn't be dereferenced (we still aren't dereferencing one), and
that an explicitly cast null pointer lacks type information (a claim
which is hard to swallow).

What we have not heard is a convincing explanation of why the cited
construct should be considered harmful.  No excuse for an
implementation that might blow up on it has been given.  Further,
no useful alternative has (to date) shown up.
-- 
Cutting half of passenger service | {bpa,uunet}!cdin-1!cdis-1!tanner
Mulroney: "cold froze our brains" | {attctc gatech!uflorida}!ki4pv!cdis-1!tanner



More information about the Comp.lang.c mailing list