Is there a static_assert replacement which satisfies the C99 standard?

c++, c++11, c99, static-assert

Solution

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; \
})

Problem

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 text message being passed to `static_assert` as a `const char*`? I can get the compiler to write a message like `A_is_not_POD`. This is what I have: ``` #define MY_STATIC_ASSERT(condition, name) \ typedef char name[(condition) ? 1 : -1]; ``` But it would be quite nice to get the compiler to write something like `"Error: A is not POD."` Any suggestions?

Original source

Related problems