sizeof a struc field

Dr. T. Andrews tanner at cdis-1.uucp
Tue Sep 26 01:52:50 AEST 1989


In article <11120 at smoke.BRL.MIL>, gwyn at smoke.BRL.MIL (Doug Gwyn) writes:
> (((struct abc *)0)->ghi) is not a valid unary expression,
> because the left-hand operand of the -> is not an lvalue
> that points at an object (see 3.3.2.3 Semantics).

This is useful (mainly as an example of the distinction between
"useful" and "very useful").  Consider...
	sizeof(p->member)		/* size of specified member */
for
	struct blunge *p;

a) If "p" hasn't yet been initialized, is it a valid expression?
b) If "p" has been initialized to NULL, is it a valid expression?
c) If "p" has been free()d, is it a valid expression?

Of course, we might also ask about *p in another way: when is
the expression
	p = (struct blunge *)malloc(sizeof(*p))
valid?  Only AFTER it has been evaluated?

If allowing case (b) above, kindly point out the distinction between
it and
	#define	p	((struct blunge *)0)
If disallowing case (b), kindly justify this.  Remember that we are
not evaluating the argument to sizeof().
-- 
...!bikini.cis.ufl.edu!ki4pv!cdis-1!tanner  ...!bpa!cdin-1!cdis-1!tanner
or...  {allegra attctc gatech!uflorida}!ki4pv!cdis-1!tanner



More information about the Comp.lang.c mailing list