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: <22103@paperboy.OSF.ORG> Date: 22 May 91 14:48:29 GMT References: <1991May20.212338.24349@thyme.jpl.nasa.gov> <16211@smoke.brl.mil> <22051@paperboy.OSF.ORG> <16220@smoke.brl.mil> Sender: news@OSF.ORG Organization: Open Software Foundation Lines: 25 In article <16220@smoke.brl.mil>, gwyn@smoke.brl.mil (Doug Gwyn) writes: |> In article <22051@paperboy.OSF.ORG> dbrooks@osf.org (David Brooks) writes: |> >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. |> |> No, you don't. If you understood my example, you should be able to apply |> the technique whenever you can latch onto, for example, a pointer to a |> struct of the appropriate type. As I said, the ubiquitous uses in X don't have that luxury. |> The X11 source code style is ATROCIOUS and should not be used as a model. Oh, I agree with that. Looking at the macro, I'm always astounded that it works. However, the fact is, in two years of supporting folks using X, I've never come across a pre-ANSI compiler that failed to handle the X macro. And, for ANSI compilers, with an official offsetof, it's moot. -- David Brooks dbrooks@osf.org Systems Engineering, OSF uunet!osf.org!dbrooks