structure element offsets
Jonathan Hahn
hahn at fred
Wed Nov 26 11:32:30 AEST 1986
In article <1096 at spice.cs.cmu.edu> bader at spice.cs.cmu.edu (Miles Bader) writes:
>Is there any way of finding the offset of a structure element from
>the beginning of a structure in a portable AND efficient way?
Try:
#define OFFSET(elem, type) (&(((type *)0)->elem))
This utilizes a pointer of address 0, for which the address of the
element reference yeilds the offset of the element.
-jonathan hahn
hahn at ames-nas.arpa
More information about the Comp.lang.c
mailing list