projects
/
project
/
libubox.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
cdb9f71
)
list.h: implement type safety for container_of()
author
Felix Fietkau
<nbd@openwrt.org>
Mon, 18 Mar 2013 04:54:44 +0000
(
05:54
+0100)
committer
Felix Fietkau
<nbd@openwrt.org>
Mon, 18 Mar 2013 04:55:00 +0000
(
05:55
+0100)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
list.h
patch
|
blob
|
history
diff --git
a/list.h
b/list.h
index 47ce33b51c45ec61cf90bad1cf182d67734eb2b7..ab52acff2f82ffbe41592144f5f193b161090521 100644
(file)
--- 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 {