Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!sharkey!cfctech!teemc!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: <7653@cdis-1.uucp> Date: 2 Oct 89 14:33:59 GMT References: <7710@microsoft.UUCP> <11086@smoke.BRL.MIL> <131@dtoa3.dt.navy.mil> <11185@smoke.BRL.MIL> Organization: Society to Preserve the Sand Gnat Lines: 30 In article <11185@smoke.BRL.MIL>, gwyn@smoke.BRL.MIL (Doug Gwyn) writes: > You're not allowed to feed garbage to sizeof(). ((type *)0)->anything > is garbage. For some looping construct with "struct blunge *p;", then, we have the interesting cases: for ( p=0 ;; ) { /* p == (type *)0 */ /* ... */ if (some_cond1) sz = sizeof(p->member); /* garbage? */ if (some_cond2) p = p_malloc(sizeof(*p)); /* garbage? */ /* ... */ } Remember that sizeof() is a compile-time operation. Do we expect the compiler to do flow analysis to determine whether we are feeding a valid pointer into a sizeof() expression? I should be pleased to hear WHY (((type *)0)->anything) is disallowed in the context of compile-time expressions. Is there some existing compiler in which it is disallowed (why?) or has X3J11, after some careful consideration, noted that there is good reason to discourage it? Note that the bald assertion that it is "garbage" is a little hard to swallow. -- ...!bikini.cis.ufl.edu!ki4pv!cdis-1!tanner ...!bpa!cdin-1!cdis-1!tanner or... {allegra attctc gatech!uflorida}!ki4pv!cdis-1!tanner