[MPlayer-G2-dev] Re: g2 config - restart...

D Richard Felker III dalias at aerifal.cx
Thu May 15 00:05:57 CEST 2003


On Wed, May 14, 2003 at 11:17:45PM +0300, Andriy N. Gritsenko wrote:
> >> /* macro to get relative address of x.y in struct x */
> >> #define STRUCT_OFF(x,y)		((void *)(&x.y-x))
> >I doubt that this macro really work. And even if it work it need an
> >instance to apply it to. Why don't you just take the one in m_struct.h
> >(wich is from glib.h) wich just need the declaration of the struct.
> 
> Hmm. I think you are right. Sorry. It seems I tired and I must to have a
> rest. Thank you. This is right?
> 
> #define STRUCT_OFF(x,y)  ((void *)((x *)0)->y)

Huh? No way, it doesn't even evaluate to an int/offset, so there's no
way it can be right!! Try this:

#define STRUCT_OFF(x,y) (((char *)&((x *)0)->y)-((char *)0))

Taking the difference of pointers makes it evaluate to an offset type,
as desired. It also handles the (nonsense) case where the null pointer
is not all 0 bits, if we care about such stupid systems. :)

Rich



More information about the MPlayer-G2-dev mailing list