aboutsummaryrefslogtreecommitdiff
path: root/src/lib/cc
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2018-06-29 10:23:52 -0400
committerNick Mathewson <nickm@torproject.org>2018-06-29 12:21:52 -0400
commit207fc4cffe21b58b7f0447706a903e5f66b8bcd8 (patch)
tree227fddeea8281eac9b95a351c4f733ada1906034 /src/lib/cc
parent77bc65bbc495095d4d2679631e06a498ea1e2529 (diff)
downloadtor-207fc4cffe21b58b7f0447706a903e5f66b8bcd8.tar.gz
tor-207fc4cffe21b58b7f0447706a903e5f66b8bcd8.zip
Move SUBTYPE_P into compat_compiler.h
Diffstat (limited to 'src/lib/cc')
-rw-r--r--src/lib/cc/compat_compiler.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/lib/cc/compat_compiler.h b/src/lib/cc/compat_compiler.h
index 67d945cfaf..c631a7e821 100644
--- a/src/lib/cc/compat_compiler.h
+++ b/src/lib/cc/compat_compiler.h
@@ -253,6 +253,18 @@
*/
#define STRUCT_VAR_P(st, off) ((void*) ( ((char*)(st)) + (off) ) )
+/** Macro: yield a pointer to an enclosing structure given a pointer to
+ * a substructure at offset <b>off</b>. Example:
+ * <pre>
+ * struct base { ... };
+ * struct subtype { int x; struct base b; } x;
+ * struct base *bp = &x.base;
+ * struct *sp = SUBTYPE_P(bp, struct subtype, b);
+ * </pre>
+ */
+#define SUBTYPE_P(p, subtype, basemember) \
+ ((void*) ( ((char*)(p)) - offsetof(subtype, basemember) ))
+
/** Macro: Yields the number of elements in array x. */
#define ARRAY_LENGTH(x) ((sizeof(x)) / sizeof(x[0]))