Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!haven!mimsy!dtoa3!dtix!stuart From: stuart@dtix.dt.navy.mil (Pearlman) Newsgroups: comp.lang.c Subject: Re: sizeof a struc field Message-ID: <131@dtoa3.dt.navy.mil> Date: 19 Sep 89 14:03:00 GMT References: <7710@microsoft.UUCP> <11086@smoke.BRL.MIL> Sender: news@dtoa3.dt.navy.mil Reply-To: stuart@dtix.dt.navy.mil (Stuart Pearlman) Organization: David Taylor Research Center, Bethesda, MD Lines: 24 In article <11086@smoke.BRL.MIL> gwyn@smoke.BRL.MIL (Doug Gwyn) writes: :In article <7710@microsoft.UUCP> peterwu@microsoft.UUCP (Peter Wu ) writes: :>What's the simplest way to obtain the sizeof a field inside a struc :>without declaring a variable? :>struct abc { :> int def; :> char ghi; :> long jkl; :>}; :>I know this works: :>#define SIZEGHI sizeof(((struct abc *)0)->ghi) : :No, that doesn't necessarily work. Review the interminable discussions :about use of null pointers. I don't see what is wrong with Peter's method. Sizeof gets evaluated at compile time. In some instances, the address of its argument may not yet have been fixed by the compiler when it is evaluated. What is important is the type of sizeof's argument, and that certainly seems well defined. Or am I totally confused? Stuart Pearlman Hadron, Inc. 9990 Lee Hway. Fairfax, VA 22030 (703) 359-6100