[DTrace-devel] [PATCH v3 05/21] compiler: add static assertions

Nick Alcock nick.alcock at oracle.com
Tue Jan 16 21:13:01 UTC 2024


C11 provides static assertions, and some compilers provide them even before
C11: so allow them to be used if available, to get earlier warning of
compile-time problems.

Signed-off-by: Nick Alcock <nick.alcock at oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees at oracle.com>
---
 include/sys/compiler.h | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/include/sys/compiler.h b/include/sys/compiler.h
index 82066e5e48d5..766a955346e8 100644
--- a/include/sys/compiler.h
+++ b/include/sys/compiler.h
@@ -8,6 +8,8 @@
 #ifndef _SYS_COMPILER_H
 #define _SYS_COMPILER_H
 
+#include <assert.h>
+
 /*
  * Attributes that vary on a compiler-by-compiler basis.
  */
@@ -56,4 +58,11 @@
 #define _dt_unused_
 
 #endif
+
+/* < C11? turn static assertions into ordinary assertions.  */
+
+#if (!defined (__STDC_VERSION__) || __STDC_VERSION__ < 201112L) && !defined(_Static_assert)
+#define _Static_assert(cond, err) assert(cond)
+#endif
+
 #endif
-- 
2.43.0.272.gce700b77fd




More information about the DTrace-devel mailing list