[PATCH xserver 1/1] list: Use offsetof() to determine member offsets within a structure
alan.coopersmith at oracle.com
Wed Aug 29 08:09:14 PDT 2012
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).
-Alan Coopersmith- alan.coopersmith at oracle.com
Oracle Solaris Engineering - http://blogs.oracle.com/alanc
More information about the xorg-devel