Useful assertion macros in C which include debug information like file, line number and error message.
This file contains 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
// These require compiler support for statement expressions (https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html) | |
#define assert_ok(e) ({int x = (e); if (x < 0) { printf("%s:%d: ", __FILE__, __LINE__); fflush(stdout); perror(#e); abort(); } x;}) | |
#define assert_ptr(e) ({void* p = (e); if (p == NULL) { printf("%s:%d: %s: NULL pointer returned\n", __FILE__, __LINE__, #e); abort(); } p;}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment