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

Ran Benita ran234 at gmail.com
Wed Aug 29 00:29:29 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.

typeof is not in c99 (or any other standard). I also think that using
XORG_DEFAULT_OPTIONS from xorg-macros would emit a warning when using
typeof. Just shoving AC_C_TYPEOF in configure.ac works, though.

> 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.
> 
> 
> --Jeremy


More information about the xorg-devel mailing list