delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/01/26/02:50:59

Date: Tue, 26 Jan 1999 09:48:12 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: "John S. Fine" <johnfine AT erols DOT com>
cc: djgpp AT delorie DOT com
Subject: Re: Strange pointer manipulation
In-Reply-To: <36AD11AA.3876@erols.com>
Message-ID: <Pine.SUN.3.91.990126094737.16926J-100000@is>
MIME-Version: 1.0
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.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019