Skip to content

Instantly share code, notes, and snippets.

@pervognsen
Last active June 13, 2021 03:06
Show Gist options
  • Save pervognsen/9d46bf9b9187cb7f89d64132dc586e07 to your computer and use it in GitHub Desktop.
Save pervognsen/9d46bf9b9187cb7f89d64132dc586e07 to your computer and use it in GitHub Desktop.
void assert_func(int cond, const char *msg) {
if (!cond) {
fprintf(stderr, "assert failed: %s\n", msg);
abort();
}
}
#define assert_helper(x, y, ...) assert_func(x, y)
#define assert(x, ...) assert_helper((x), ## __VA_ARGS__, #x)
int main(int argc, char **argv) {
assert(argc > 0);
assert(argv[0] != 0, "argv[0] cannot be null");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment