lkml.org 
[lkml]   [2015]   [Jul]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[RFC PATCH 01/16] typecheck_member and offsetof_t
Date
Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
---

include/linux/stddef.h | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/include/linux/stddef.h b/include/linux/stddef.h
index 9c61c7cda936..e60bd164c03a 100644
--- a/include/linux/stddef.h
+++ b/include/linux/stddef.h
@@ -27,4 +27,11 @@ enum {
#define offsetofend(TYPE, MEMBER) \
(offsetof(TYPE, MEMBER) + sizeof(((TYPE *)0)->MEMBER))

+#define typecheck_member(TYPE, MEMBER, MEMBERTYPE) \
+ ((size_t)(&((TYPE *)0)->MEMBER - (MEMBERTYPE*)0) ? 0 : 0)
+
+/* like offsetof(), but ensures that MEMBER is of type MEMBERTYPE */
+#define offsetof_t(TYPE, MEMBER, MEMBERTYPE) \
+ (typecheck_member(TYPE, MEMBER, MEMBERTYPE) + offsetof(TYPE, MEMBER))
+
#endif
--
2.4.3


\
 
 \ /
  Last update: 2015-07-21 16:21    [W:1.000 / U:0.308 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site