Created
August 30, 2012 00:14
-
-
Save kylesluder/3520840 to your computer and use it in GitHub Desktop.
Optional assertion description argument
This file contains hidden or 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
#include <stdio.h> | |
static inline void _AssertionFailed(char *expr, char *reason) | |
{ | |
if (!reason || *reason == '\0') | |
printf("Assertion failed: %s\n", expr); | |
else | |
printf("Assertion failed: %s (Reason: %s)\n", expr, reason); | |
} | |
#define ASSERTN(expr, ...) _AssertionFailed(#expr, "" __VA_ARGS__) | |
#define ASSERT(...) ASSERTN(__VA_ARGS__) | |
int main(int argc, char **argv) { | |
// Without a reason: | |
ASSERT(0); | |
// With a reason: | |
ASSERT(0, "Should not get here"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment