Skip to content

Instantly share code, notes, and snippets.

Created August 8, 2017 22:14
Show Gist options
  • Save anonymous/14c7a58912b74c6511e3c1377510a060 to your computer and use it in GitHub Desktop.
Save anonymous/14c7a58912b74c6511e3c1377510a060 to your computer and use it in GitHub Desktop.
assert
#define DEBUGBREAK() __ud2()
#ifdef NDEBUG
#define ASSERT(x) __assume(x)
#define ASSERT_IF(cond, x)
#define ASSERT_IFF(cond, x)
#define ASSERT_IF_ELSE(cond, x, y)
#define ASSERTED_EXPRIF(x, t, f) ( (x) ? (t) : (f) )
#else
#define ASSERT(x) do { if(!(x)) DEBUGBREAK(); } while(0)
#define ASSERT_IF(cond, x) do { if(cond) if(!(x)) DEBUGBREAK(); } while(0)
#define ASSERT_IFF(cond, x) do { if(cond) { if(!(x)) DEBUGBREAK(); } else { if(x) DEBUGBREAK(); } } while(0)
#define ASSERT_IF_ELSE(cond, x, y) do { if(cond) { if(!(x)) DEBUGBREAK(); } else { if(!(y)) DEBUGBREAK(); } } while(0)
#define ASSERTED_EXPRIF(x, t, f) ( (x) ? (t) : DEBUGBREAK(),(f) )
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment