Need macro to get offset within a structure

Erik Naggum enag at ifi.uio.no
Tue Feb 19 23:12:16 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

I snatched this from /local/lib/gcc-include/stddef.h.

#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)

This works like a charm on a vast number of compilers I've used.

--
[Erik Naggum]					     <enag at ifi.uio.no>
Naggum Software, Oslo, Norway			   <erik at naggum.uu.no>



More information about the Comp.lang.c mailing list