diff options
author | Felix Fietkau <nbd@openwrt.org> | 2013-03-18 08:54:44 +0400 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2013-03-18 08:55:00 +0400 |
commit | 009b4d574e88d558a9a9278cff363cee38b9e041 (patch) | |
tree | 4515534a96efcefc14ec20891c29ab89ba3f7826 /list.h | |
parent | cdb9f71971062bfeaf4352621249f9d3d2408f1b (diff) |
list.h: implement type safety for container_of()
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Diffstat (limited to 'list.h')
-rw-r--r-- | list.h | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -35,8 +35,11 @@ #define prefetch(x) #ifndef container_of -#define container_of(ptr, type, member) ( \ - (type *)( (char *)ptr - offsetof(type,member) )) +#define container_of(ptr, type, member) \ + ({ \ + const typeof(((type *) NULL)->member) *__mptr = (ptr); \ + (type *) ((char *) __mptr - offsetof(type, member)); \ + }) #endif struct list_head { |