]> git.proxmox.com Git - mirror_spl.git/commitdiff
This patch add a CTASSERT macro for compile time assertion.
authorYuxuan Shui <yshuiv7@gmail.com>
Fri, 1 Nov 2013 16:14:05 +0000 (00:14 +0800)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Mon, 14 Apr 2014 16:28:53 +0000 (09:28 -0700)
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 <yshuiv7@gmail.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #303

include/sys/debug.h

index f3f3529a9cb331335e1dfa9b4fd778eab01286c9..9fa2653d4d3b61f614a22bddf471e220c3d65e61 100644 (file)
@@ -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 */