From e50025cc7da5456feaa232dc26492595dbf0e398 Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Thu, 27 Sep 2018 19:59:29 +0200 Subject: [PATCH] static_assert - portable solution compatible with C++98 --- Firmware/menu.cpp | 1 + Firmware/static_assert.h | 23 +++++++++++++++++++++++ Firmware/ultralcd.cpp | 3 +++ 3 files changed, 27 insertions(+) create mode 100644 Firmware/static_assert.h diff --git a/Firmware/menu.cpp b/Firmware/menu.cpp index bd523826..e2fea672 100644 --- a/Firmware/menu.cpp +++ b/Firmware/menu.cpp @@ -10,6 +10,7 @@ #include "Marlin.h" #include "ultralcd.h" #include "language.h" +#include "static_assert.h" diff --git a/Firmware/static_assert.h b/Firmware/static_assert.h new file mode 100644 index 00000000..41007979 --- /dev/null +++ b/Firmware/static_assert.h @@ -0,0 +1,23 @@ +//static_assert.h +//portable solution compatible with C++98 + +#if (__cplusplus < 201103L) //std < C++11 + +//source http://www.pixelbeat.org/programming/gcc/STATIC_ASSERT.html +#define ASSERT_CONCAT_(a, b) a##b +#define ASSERT_CONCAT(a, b) ASSERT_CONCAT_(a, b) + +// These can't be used after statements in c89. +#ifdef __COUNTER__ + #define static_assert(e,m) \ + ;enum { ASSERT_CONCAT(STATIC_ASSERT_, __COUNTER__) = 1/(int)(!!(e)) } +#else + //This can't be used twice on the same line so ensure if using in headers + //that the headers are not included twice (by wrapping in #ifndef...#endif) + //Note it doesn't cause an issue when used on same line of separate modules + //compiled with gcc -combine -fwhole-program. + #define static_assert(e,m) \ + ;enum { ASSERT_CONCAT(assert_line_, __LINE__) = 1/(int)(!!(e)) } +#endif //__COUNTER__ + +#endif //(__cplusplus < 201103L) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 510114c9..fef61d72 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -37,6 +37,9 @@ #include "mmu.h" +#include "static_assert.h" + + extern bool fans_check_enabled;