Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!wuarchive!hsdndev!cmcl2!adm!smoke!gwyn From: gwyn@smoke.brl.mil (Doug Gwyn) Newsgroups: comp.lang.c Subject: Re: finding offset of a member in C structures Message-ID: <16220@smoke.brl.mil> Date: 22 May 91 00:45:09 GMT References: <1991May20.212338.24349@thyme.jpl.nasa.gov> <16211@smoke.brl.mil> <22051@paperboy.OSF.ORG> Organization: U.S. Army Ballistic Research Laboratory, APG, MD. Lines: 12 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. The X11 source code style is ATROCIOUS and should not be used as a model.