Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.openwrt.org/project/libubox.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/list.h
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2013-03-18 08:54:44 +0400
committerFelix Fietkau <nbd@openwrt.org>2013-03-18 08:55:00 +0400
commit009b4d574e88d558a9a9278cff363cee38b9e041 (patch)
tree4515534a96efcefc14ec20891c29ab89ba3f7826 /list.h
parentcdb9f71971062bfeaf4352621249f9d3d2408f1b (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.h7
1 files changed, 5 insertions, 2 deletions
diff --git a/list.h b/list.h
index 47ce33b..ab52acf 100644
--- a/list.h
+++ b/list.h
@@ -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 {