mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-01-08 00:00:14 +01:00
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>
This commit is contained in:
parent
695facc130
commit
3236ee0d90
1 changed files with 3 additions and 2 deletions
|
|
@ -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); \
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue