Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!nike!fred!hahn From: hahn@fred (Jonathan Hahn) Newsgroups: comp.lang.c Subject: Re: structure element offsets Message-ID: <768@nike.UUCP> Date: Tue, 25-Nov-86 20:32:30 EST Article-I.D.: nike.768 Posted: Tue Nov 25 20:32:30 1986 Date-Received: Tue, 25-Nov-86 22:40:53 EST References: <1096@spice.cs.cmu.edu> Sender: usenet@nike.UUCP Reply-To: hahn@ames-nas.arpa (Jonathan Hahn) Organization: NASA Ames, Mountain View, CA Lines: 13 Keywords: structure, offset In article <1096@spice.cs.cmu.edu> bader@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@ames-nas.arpa