diff options
author | Gabriel Laskar <gabriel@lse.epita.fr> | 2017-05-14 16:33:16 +0200 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2017-05-15 10:21:51 +1000 |
commit | 3236ee0d905dc24421d01b81e1792a72dd7dae31 (patch) | |
tree | 4929d17252318d628294c0685642ab2423de1d28 /src | |
parent | 695facc1302a9f252b566d4710991fa9a2d8333d (diff) |
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 <gabriel@lse.epita.fr>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'src')
-rw-r--r-- | src/libinput-util.h | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/libinput-util.h b/src/libinput-util.h index 9ecded7..6d9bbe2 100644 --- a/src/libinput-util.h +++ b/src/libinput-util.h @@ -34,6 +34,7 @@ #include <math.h> #include <stdarg.h> #include <stdbool.h> +#include <stddef.h> #include <stdio.h> #include <string.h> #include <time.h> @@ -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); \ |