[PATCH libinput 1/5] util: drop GCC specifics for container_of

Peter Hutterer peter.hutterer at who-t.net
Thu May 11 22:11:10 UTC 2017


On Wed, May 10, 2017 at 01:07:23PM +0200, Gabriel Laskar wrote:
> On Wed, May 10, 2017 at 01:47:56PM +1000, Peter Hutterer wrote:
> > clang supports __typeof__ which was the only real difference. Not sure any
> > other compilers matter (that don't support __typeof__)
> > 
> > Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
> > ---
> >  src/libinput-util.h | 6 ------
> >  1 file changed, 6 deletions(-)
> > 
> > diff --git a/src/libinput-util.h b/src/libinput-util.h
> > index 4e97e011..a9a2b660 100644
> > --- a/src/libinput-util.h
> > +++ b/src/libinput-util.h
> > @@ -85,15 +85,9 @@ void list_insert(struct list *list, struct list *elm);
> >  void list_remove(struct list *elm);
> >  bool list_empty(const struct list *list);
> >  
> > -#ifdef __GNUC__
> >  #define container_of(ptr, sample, member)				\
> >  	(__typeof__(sample))((char *)(ptr)	-			\
> >  		 ((char *)&(sample)->member - (char *)(sample)))
> 
> Is there any reason for container_of to not use offsetof defined in
> stddef.h?

good point, none that I could think of. Best I can think of is that a lot of
these macros wander from project to project and there's a few where support
of old C standards prohibit certain features. This doesn't apply for us in
libinput though. Care to submit a patch?

Cheers,
   Peter


More information about the wayland-devel mailing list