utils/macros.h: Introduce a `STATIC_ASSERT' macro.
[mLib] / utils / macros.h
index 5f432f7..9e27a48 100644 (file)
@@ -34,6 +34,8 @@
 
 /*----- Header files ------------------------------------------------------*/
 
+#include <assert.h>
+
 #ifndef MLIB_COMPILER_H
 #  include "compiler.h"
 #endif
 #define MLIB__GLUE(x, y) x##y
 #define GLUE(x, y) MLIB__GLUE(x, y)
 
+#ifdef static_assert
+#  define STATIC_ASSERT(cond, msg) static_assert(cond, msg)
+#else
+#  define STATIC_ASSERT(cond, msg)                                     \
+       IGNORABLE extern char static_assert_failed[2*!!(cond) - 1]
+#endif
+
 /*----- Compiler diagnostics ----------------------------------------------*/
 
 /* --- Compiler-specific definitions --- */