Skip to content

Instantly share code, notes, and snippets.

@saghul
Created September 22, 2011 21:06
Show Gist options
  • Save saghul/1236055 to your computer and use it in GitHub Desktop.
Save saghul/1236055 to your computer and use it in GitHub Desktop.
Custom assertion macro that is not disabled by NDEBUG
#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