Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!spool.mu.edu!sdd.hp.com!wuarchive!mit-eddie!bloom-beacon!eru!hagbard!sunic!ugle.unit.no!nuug!ifi!enag From: enag@ifi.uio.no (Erik Naggum) Newsgroups: comp.lang.c Subject: Re: Need macro to get offset within a structure Message-ID: Date: 19 Feb 91 12:12:16 GMT References: <1991Feb16.232713.6001@runx.oz.au> Sender: enag@ifi.uio.no (Erik Naggum) Organization: Naggum Software, Oslo, Norway Lines: 14 In-Reply-To: richardm@runx.oz.au's message of 16 Feb 91 23:27:13 GMT In article <1991Feb16.232713.6001@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] Naggum Software, Oslo, Norway