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

Jeremy Sequoia jeremyhu at apple.com
Tue Aug 28 23:59:34 PDT 2012

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.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.x.org/archives/xorg-devel/attachments/20120828/b5af79d8/attachment.html>

More information about the xorg-devel mailing list