Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!ames!ncar!asuvax!mcdphx!xroads!hrc!zardoz!tgate!ka3ovk!ki4pv!cdis-1!tanner From: tanner@cdis-1.uucp (Dr. T. Andrews) Newsgroups: comp.lang.c Subject: Re: sizeof a struc field Message-ID: <7646@cdis-1.uucp> Date: 25 Sep 89 15:52:50 GMT References: <7710@microsoft.UUCP> <11086@smoke.BRL.MIL> <131@dtoa3.dt.navy.mil> <11120@smoke.BRL.MIL> Organization: Society to Preserve the Sand Gnat Lines: 28 In article <11120@smoke.BRL.MIL>, gwyn@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