Skip to content

Instantly share code, notes, and snippets.

@dylnuge
Created September 22, 2012 04:22
Show Gist options
  • Save dylnuge/3765106 to your computer and use it in GitHub Desktop.
Save dylnuge/3765106 to your computer and use it in GitHub Desktop.
Debugging Macros for C
// 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
@dylnuge
Copy link
Author

dylnuge commented Sep 22, 2012

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment