From: Gabriel Laskar Date: Sun, 14 May 2017 14:33:16 +0000 (+0200) Subject: util: use offsetof in container_of X-Git-Tag: 1.7.901~55 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3236ee0d905dc24421d01b81e1792a72dd7dae31;p=platform%2Fupstream%2Flibinput.git util: use offsetof in container_of gcc and clang supports offsetof (defined in stddef.h) as defined by C99 and POSIX.1-2001, use it in container_of. Signed-off-by: Gabriel Laskar Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- diff --git a/src/libinput-util.h b/src/libinput-util.h index 9ecded7e..6d9bbe23 100644 --- a/src/libinput-util.h +++ b/src/libinput-util.h @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -86,8 +87,8 @@ void list_remove(struct list *elm); bool list_empty(const struct list *list); #define container_of(ptr, sample, member) \ - (__typeof__(sample))((char *)(ptr) - \ - ((char *)&((typeof(sample))0)->member)) + (__typeof__(sample))((char *)(ptr) - \ + offsetof(__typeof__(*sample), member)) #define list_for_each(pos, head, member) \ for (pos = 0, pos = container_of((head)->next, pos, member); \