Need macro to get offset within a structure
Bjorn Engsig
bengsig at dk.oracle.com
Thu Feb 21 23:36:41 AEST 1991
In article <1991Feb16.232713.6001 at runx.oz.au>, Richard Murnane writes:
|Does anybody know a decent macro to find the offset of an element
|in a structure
And in article <ENAG.91Feb19131201 at holmenkollen.ifi.uio.no> enag at ifi.uio.no
(Erik Naggum) replied:
|#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
|This works like a charm on a vast number of compilers I've used.
Actually, ANSI C includes an offsetof macro in <stddef.h>. And please do
not enter the usual discussion of wheather the macro definition above is
valid ANSI C or not. The rationale of the ANSI C will fill you in with the
details of this.
--
Bjorn Engsig, ORACLE Corporation, E-mail: bengsig at oracle.com, bengsig at oracle.nl
"Stepping in others footsteps, doesn't bring you ahead"
More information about the Comp.lang.c
mailing list