Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!apple!oliveb!amiga!cbmvax!jesup From: jesup@cbmvax.UUCP (Randell Jesup) Newsgroups: comp.sys.amiga.tech Subject: Re: Determining structure field offsets Message-ID: <6654@cbmvax.UUCP> Date: 20 Apr 89 22:32:32 GMT References: <9270@watcgl.waterloo.edu> <17372@cup.portal.com> <11940@grebyn.COM> <38874@bbn.COM> Reply-To: jesup@cbmvax.UUCP (Randell Jesup) Distribution: usa Organization: Commodore Technology, West Chester, PA Lines: 16 In article <38874@bbn.COM> cosell@BBN.COM (Bernie Cosell) writes: >In article <11940@grebyn.COM> ckp@grebyn.COM (Checkpoint Technologies) writes: >} >}Someone asked about calculating structure member offsets in a portable >}way. You were close, but try this: ... >You don't need the dummy variable: it is legal in C (although I don't know >for ANSI C) to coerce the address '0' to be a pointer to anything. And so > #define offset(s,f) &(((s *)0)->f) >works just fine. Lattice 5.02 has an offsetof() macro in stddef.h (where ANSI says it should be). -- Randell Jesup, Commodore Engineering {uunet|rutgers|allegra}!cbmvax!jesup