Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!shadooby!samsung!ginosko!aplcen!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn) Newsgroups: comp.lang.c Subject: Re: sizeof a struc field Message-ID: <11426@smoke.BRL.MIL> Date: 27 Oct 89 18:10:31 GMT References: <7710@microsoft.UUCP> <4700046@m.cs.uiuc.edu> Reply-To: gwyn@brl.arpa (Doug Gwyn) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 21 In article <4700046@m.cs.uiuc.edu> kenny@m.cs.uiuc.edu writes: >#define NEW(p) ((p) = malloc_and_check ((size_t) (sizeof *(p)))) >[appears to be claimed to be] illegal under the proposed >standard, because it dereferences the uninitialized pointer p. No, there is nothing wrong with that; the argument of sizeof is not evaluated, and so a reference via the uninitialized pointer cannot occur. Since I'm the one claiming that sizeof(((foo*)0)->member) is invalid, let me try ONE MORE TIME to clarify what I think makes it invalid. It is invalid because the operand of sizeof is invalid, and the operand of sizeof is invalid because you are not allowed to write ((foo*)0)->member EVEN THOUGH the null pointer does have type "pointer to foo" (and we are assuming that foo objects do have "member" member designators). I believe that a compiler is allowed to diagnose that construct as an abuse of a null pointer constant. There may be Standard-wise people who disagree with me on this, but I haven't been getting much valid counterargument from them. There HAS been a lot of argument against points that I did not think I was trying to make!