Need macro to get offset within a structure

Dr. David Curtis dcurtis at crc.ac.uk
Thu Feb 21 23:43:31 AEST 1991


In article <1991Feb16.232713.6001 at runx.oz.au> richardm at runx.oz.au (Richard Murnane) writes:
>Hi all,
>Does anybody know a decent macro to find the offset of an element
>in a structure?

How about:

#define offset(str,el) ((char*) &((str*)NULL)->el - (char*) NULL)



More information about the Comp.lang.c mailing list