Created
September 22, 2012 04:22
-
-
Save dylnuge/3765106 to your computer and use it in GitHub Desktop.
Debugging Macros for C
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
// Define debugging macros. Because actual code shouldn't be littered with | |
// debugging printfs and sanity check assertations. | |
#ifdef DEBUG | |
#define debug_assert(...) assert(__VA_ARGS__) | |
#define debug_printf(...) printf(__VA_ARGS__) | |
#else | |
#define debug_assert(...) ; | |
#define debug_printf(...) ; | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some notes: debug_assert is useful for some assert functions, including the one I'm using in my malloc code. It's probably not needed if you're using <assert.h>, since if
NDEBUG
is defined before assert.h is included, the assert function is replaced with a NOP.