[PATCH xserver 1/1] list: Use offsetof() to determine member offsets within a structure
Mark Kettenis
mark.kettenis at xs4all.nl
Wed Aug 29 12:28:46 PDT 2012
> Date: Wed, 29 Aug 2012 08:09:14 -0700
> From: Alan Coopersmith <alan.coopersmith at oracle.com>
>
> On 08/28/12 11:59 PM, 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.
>
> Actually, as best I can tell, typeof is not in any standard, just a
> gcc extension that's been picked up by compilers that want to be gcc
> compatible. (And yes, for my sins, I do have a copy of the C11
> standard in front of me.)
>
> If AC_C_TYPEOF works, then I'm happy with that, otherwise a little
> quick testing shows it seems to work with Sun compilers matching an
> #if test of: (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590))
> (i.e. Studio 12.0 or later - latest release is 12.3).
Well, AC_C_TYPEOF doesn't really work. It will define HAVE_TYPEOF if
typeof() (or an equivalent) is available. But you'll still have to
provde an alternative implementation.
Jeremy, did clang actually complain about __container_of() as well, or
was the change to that function just an optimization?
More information about the xorg-devel
mailing list