Date: Tue, 26 Jan 1999 09:48:12 +0200 (IST) From: Eli Zaretskii X-Sender: eliz AT is To: "John S. Fine" cc: djgpp AT delorie DOT com Subject: Re: Strange pointer manipulation In-Reply-To: <36AD11AA.3876@erols.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Reply-To: djgpp AT delorie DOT com On Mon, 25 Jan 1999, John S. Fine wrote: > FOO *xxx; > int *b_ptr; > b_ptr = & (xxx->b); > > Assume I know which element it points to and I know which > kind of structure it is, but I don't know which instance > of the structure it is. I want undot to compute that, so > that undot( b_ptr, FOO, b ) would compute the address > that started out in xxx. This is UNTESTED: #define undot(ptr,st,mbr) ((st *)((char *)(ptr) - offsetof(st,mbr))) > I don't need portable C; A GCC specific kludge would be > fine. No need for any GCC-specific magic: `offsetof' is ANSI C. It's amazing how many people miss that feature.