Created
January 18, 2021 07:52
-
-
Save EvanMu96/88d4d7537b0ec47e5973d23332040ff6 to your computer and use it in GitHub Desktop.
runtime && compiletime c++ assertion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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