Mail Archives: djgpp/1999/01/26/02:50:59
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.
- Raw text -