finding offset of a member in C structures

Doug Gwyn gwyn at smoke.brl.mil
Wed May 22 10:45:09 AEST 1991


In article <22051 at paperboy.OSF.ORG> dbrooks at 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.



More information about the Comp.lang.c mailing list