[PATCH xserver 1/1] list: Use offsetof() to determine member offsets within a structure

Peter Hutterer peter.hutterer at who-t.net
Wed Aug 29 00:51:57 PDT 2012


On Tue, Aug 28, 2012 at 11:59:34PM -0700, Jeremy Sequoia wrote:
> On 08/28/12, Peter Hutterer  <peter.hutterer at who-t.net> wrote:
> 
> > > -#define __container_of(ptr, sample, member)                        	\
> > > -    (void *)((char *)(ptr)                                        	\
> > > -             - ((char *)&(sample)->member - (char *)(sample)))
> > > +#define __container_of(ptr, sample, member)                	\
> > > +    container_of(ptr, typeof(*sample), member)
> > 
> > typeof is a gcc extension/c99 and I don't think we support that yet, do we?
> > 
> I thought we were expecting C99 nowadays.  CCing Alan since I think he knows the answer to that and can chime in re: SunCC.
> 
> 
> In any event, typeof is in *a* standard whereas the previous implementation is undefined (and can lead to crashes on startup).  I'd vote for doing something that is in a 13 year old standard over something that has undefined behavior.
> 
> 
> If there is concern over this breaking gcc-3.2 or some ancient compiler, I'm happy to update it to use $ifdef guarding.  At minimum, I'd like to get this changed for __clang__ before 1.13 ships.


right, except for the typeof it's a 
Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>, 
so whatever Alan and Keith are happy with, I guess.

Cheers,
   Peter      






More information about the xorg-devel mailing list