Skip to content

Instantly share code, notes, and snippets.

@EvanMu96
Created January 18, 2021 07:52
Show Gist options
  • Save EvanMu96/88d4d7537b0ec47e5973d23332040ff6 to your computer and use it in GitHub Desktop.
Save EvanMu96/88d4d7537b0ec47e5973d23332040ff6 to your computer and use it in GitHub Desktop.
runtime && compiletime c++ assertion
// run time assert
#if ASSERTIONS_ENABLED
#define debugBreak() asm {int 3}
#define ASSERT(expr) \
if (expr) {} \
else \
{ \
reportAssertionFailure(#expr, \
__FILE__, __LINE__); \
debugBreak(); \
} \
#else
#define ASSERT(expr)
#endif
// compile time assert
#define _ASSERT_GLUE(a, b) a ## b
#define ASSERT_GLUE(a, b) _ASSERT_GLUE(a, b)
#define STATIC_ASSERT(expr) \
enum \
{ \
ASSERT_GLUE(g_assert_fail_, __LINE__) \
= 1 / (int)(!!(expr)) \
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment