[DTrace-devel] [PATCH v2 07/23] compiler: add static assertions

Nick Alcock nick.alcock at oracle.com
Mon Nov 27 16:47:13 UTC 2023


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>
---
 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.42.0.271.g85384428f1




More information about the DTrace-devel mailing list