finding offset of a member in C structures

David Brooks dbrooks at osf.org
Wed May 22 00:13:58 AEST 1991


In article <16211 at smoke.brl.mil>, gwyn at smoke.brl.mil (Doug Gwyn) writes:
|> In article <1991May20.212338.24349 at thyme.jpl.nasa.gov> kaleb at 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 at osf.org
Systems Engineering, OSF		uunet!osf.org!dbrooks



More information about the Comp.lang.c mailing list