4 ms·
Nice! Isn't this exactly assert in C++? (the following is from https://en.cppreference.com/w/cpp/error/assert https://en.cppreference.com/w/cpp/error/assert)
by darkkindness 7y ago
Nice! Isn't this exactly assert in C++? (the following is from https://en.cppreference.com/w/cpp/error/assert https://en.cppreference.com/w/cpp/error/assert)
#ifdef NDEBUG
#define assert(condition) ((void)0)
#else
#define assert(condition) /*implementation defined*/
#endif
...
assert(("There are five lights", 2 + 2 == 5));
...
test: test.cc:10: int main(): Assertion `((void)"There are five lights", 2+2==5)' failed.
Take it as a token that you are doing something right. :)
- john_moscow 7y agoAssert's run-time. This is compile-time (i.e. all instances are guaranteed to trigger during build). C++ equivalent would be a static_assert, but it has a totally different use case like this: static_assert(sizeof(StructUsedInSomeBinaryProtocol) == SomeConstantExpectedByTheOtherSide, "<...>")
- TeMPOraL 7y agoWe used to do static asserts with a preprocessor macro that typedefed an array with size expressed as: (your condition) ? 1 : -1. Point being, static asserts have the use case you want them to have; I see no reason to not have a TODO macro that expands to static_assert(false, "...").