path: root/include
diff options
authorH. Peter Anvin (Intel) <hpa@zytor.com>2018-12-14 00:27:59 -0800
committerH. Peter Anvin (Intel) <hpa@zytor.com>2018-12-14 00:27:59 -0800
commitce19a52a3422332d55d8c0f601f30c2e67c14f09 (patch)
tree08cddeca1c4f25196ad4ffd73ae3abbda4b1aa15 /include
parent374312cde4d44f8849d602cc5c9ea634798b9c50 (diff)
Define and use offsetin() instead of offsetof()
New macro which defines the offset on an object rather than a type. This macro, as far as I know, ought to be fully portable, unlike the fallback version of offsetof(). Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Diffstat (limited to 'include')
1 files changed, 7 insertions, 0 deletions
diff --git a/include/compiler.h b/include/compiler.h
index 4ce60ccc..7beeb8fe 100644
--- a/include/compiler.h
+++ b/include/compiler.h
@@ -180,6 +180,13 @@ typedef enum bool { false, true } bool;
# define offsetof(t,m) ((size_t)&(((t *)0)->m))
+/* This is like offsetof(), but takes an object rather than a type.
+ Ironically enough this is actually guaranteed to be portable,
+ as far as I know... */
+#ifndef offsetin
+# define offsetin(p,m) ((const char *)&((p).m) - (const char *)&(p))
/* The container_of construct: if p is a pointer to member m of
container class c, then return a pointer to the container of which
*p is a member. */