I have been trying to implement a method similar to static_assert
which is defined in the C++11 standard. The main problem is how does the C++ compiler write the te
Not sure i understand question, but C11 have _Static_assert(condition, errmessage)
. In C99 this functionality was missing but, depending on compiler, it could be possible to emulate. E.g. for gcc (unfortulately clang doesn't support attribute(error))
#define MY_STATIC_ASSERT(cnd, descr) ({ \
extern int __attribute__ ((error("static assert failed: (" #cnd ") (" #descr ")"))) \
compile_time_check(void); \
((cnd) ? 0 : compile_time_check()), 0; \
})