Created
September 22, 2011 21:06
-
-
Save saghul/1236055 to your computer and use it in GitHub Desktop.
Custom assertion macro that is not disabled by NDEBUG
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> | |
#include <stdlib.h> | |
#define ASSERT(x) \ | |
do { \ | |
if (!(x)) { \ | |
fprintf (stderr, "%s:%u: %s: Assertion `" #x "' failed.\n", \ | |
__FILE__, __LINE__, __func__); \ | |
abort(); \ | |
} \ | |
} while(0) \ | |
int main(int argc, const char *argv[]) | |
{ | |
char *foo = NULL; | |
ASSERT(foo != NULL); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment