Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!munnari.oz.au!goanna!ok From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) Newsgroups: comp.lang.c Subject: Re: Need macro to get offset within a structure Message-ID: <4809@goanna.cs.rmit.oz.au> Date: 21 Feb 91 05:48:44 GMT References: <1991Feb16.232713.6001@runx.oz.au> Organization: Comp Sci, RMIT, Melbourne, Australia Lines: 11 In article , enag@ifi.uio.no (Erik Naggum) writes: > 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. offsetof() being a required part of ANSI C (if you use the right header), it's clearly the right interface. You'll want an #if __STDC__ so that you get the "official" version when it's there, as the cast of zero is not portable. -- Professional programming is paranoid programming