Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!paperboy!osf.org!dbrooks From: dbrooks@osf.org (David Brooks) Newsgroups: comp.lang.c Subject: Re: finding offset of a member in C structures Message-ID: <22051@paperboy.OSF.ORG> Date: 21 May 91 14:13:58 GMT References: <1276@unisql.UUCP> <16194@smoke.brl.mil> <1991May20.212338.24349@thyme.jpl.nasa.gov> <16211@smoke.brl.mil> Sender: news@OSF.ORG Organization: Open Software Foundation Lines: 16 In article <16211@smoke.brl.mil>, gwyn@smoke.brl.mil (Doug Gwyn) writes: |> In article <1991May20.212338.24349@thyme.jpl.nasa.gov> kaleb@thyme.jpl.nasa.gov (Kaleb Keithley) writes: |> >Here's how *they* do in the X Window System. I expect it's about as |> >portable as anything gets. |> |> Wrong! I posted a portable method. The method you posted: struct a_struct foo; int offset2 = (char *)&foo.member2 - (char *)&foo; /* for example */ has an unfortunate drawback. You need to be able to declare foo, and squander space for it. The ubiquitous uses in X don't have those luxuries. -- David Brooks dbrooks@osf.org Systems Engineering, OSF uunet!osf.org!dbrooks