summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorYuxuan Shui <[email protected]>2013-11-02 00:14:05 +0800
committerBrian Behlendorf <[email protected]>2014-04-14 09:28:53 -0700
commit6c48cd8ac223eb00cb4dadebcbe4ce1dfdfc6b76 (patch)
treeb22afd33a29f169a49eb5d1f30a0b992df86c563 /include
parentacf0ade362cb8b26d67770114ee6fa17816e6b65 (diff)
This patch add a CTASSERT macro for compile time assertion.
This macro makes the compile to spit "mixed definition and code" warning, I can't find a way to avoid it. This patch lays some groundwork for the persistent l2arc feature. See https://www.illumos.org/issues/3525. Signed-off-by: Yuxuan Shui <[email protected]> Signed-off-by: Brian Behlendorf <[email protected]> Closes #303
Diffstat (limited to 'include')
-rw-r--r--include/sys/debug.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/include/sys/debug.h b/include/sys/debug.h
index f3f3529a9..9fa2653d4 100644
--- a/include/sys/debug.h
+++ b/include/sys/debug.h
@@ -145,4 +145,15 @@ do { \
#define VERIFY(x) ASSERT(x)
#endif /* NDEBUG */
+
+/*
+ * Compile-time assertion. The condition 'x' must be constant.
+ */
+#define CTASSERT_GLOBAL(x) _CTASSERT(x, __LINE__)
+#define CTASSERT(x) { _CTASSERT(x, __LINE__); }
+#define _CTASSERT(x, y) __CTASSERT(x, y)
+#define __CTASSERT(x, y) \
+ typedef char __attribute__ ((unused)) \
+ __compile_time_assertion__ ## y[(x) ? 1 : -1]
+
#endif /* SPL_DEBUG_H */