aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/beam/sys.h
diff options
context:
space:
mode:
authorSverker Eriksson <[email protected]>2014-12-02 17:37:13 +0100
committerSverker Eriksson <[email protected]>2014-12-02 17:37:13 +0100
commitb3e52c026ce4920e1a4e36ef98e5de94666e91ef (patch)
treeacd32450496744ade5043d8b56cb32b5f3dae1c2 /erts/emulator/beam/sys.h
parentc0067390b80f015a0342284505543d099b9e20e6 (diff)
downloadotp-b3e52c026ce4920e1a4e36ef98e5de94666e91ef.tar.gz
otp-b3e52c026ce4920e1a4e36ef98e5de94666e91ef.tar.bz2
otp-b3e52c026ce4920e1a4e36ef98e5de94666e91ef.zip
erts: Add compile time assert ERTS_CT_ASSERT
and usage
Diffstat (limited to 'erts/emulator/beam/sys.h')
-rw-r--r--erts/emulator/beam/sys.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/erts/emulator/beam/sys.h b/erts/emulator/beam/sys.h
index c29d4b3777..7661bf2dc7 100644
--- a/erts/emulator/beam/sys.h
+++ b/erts/emulator/beam/sys.h
@@ -189,6 +189,22 @@ __decl_noreturn void __noreturn erl_assert_error(const char* expr, const char *f
#endif
/*
+ * Compile time assert
+ * (the actual compiler error msg can be a bit confusing)
+ */
+#if ERTS_AT_LEAST_GCC_VSN__(3,1,1)
+# define ERTS_CT_ASSERT(e) \
+ do { \
+ enum { compile_time_assert__ = __builtin_choose_expr((e),0,(void)0) }; \
+ } while(0)
+#else
+# define ERTS_CT_ASSERT(e) \
+ do { \
+ enum { compile_time_assert__ = 1/(e) }; \
+ } while (0)
+#endif
+
+/*
* Microsoft C/C++: We certainly want to use stdarg.h and prototypes.
* But MSC doesn't define __STDC__, unless we compile with the -Za
* flag (strict ANSI C, no Microsoft extension). Compiling with -Za