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>
#include <math.h>
#include <stdarg.h>
#include <stdbool.h>
+#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
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); \