Xref: utzoo comp.lang.c:36362 comp.std.c:4362 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!hp4nl!orcenl!bengsig From: bengsig@dk.oracle.com (Bjorn Engsig) Newsgroups: comp.lang.c,comp.std.c Subject: Re: Need macro to get offset within a structure Message-ID: <1263@dkunix9.dk.oracle.com> Date: 21 Feb 91 12:36:41 GMT References: <1991Feb16.232713.6001@runx.oz.au> Reply-To: bengsig@dk.oracle.com (Bjorn Engsig) Followup-To: comp.std.c Organization: Oracle Denmark Lines: 17 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 And in article enag@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 . 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@oracle.com, bengsig@oracle.nl "Stepping in others footsteps, doesn't bring you ahead"