#include "debug.h" int answer(void) { return 42; } int main(void) { int num = 1; char *str = "hello"; debug(num); // => num = 1 debug(num, str, answer()); // => num = 1 // str = hello // answer() = 42 debug_raw("counting:", 1, -2, 3 + 0.4); // => counting: 1 -2 3.4 debug_raw(str, "world!"); // => hello world! idebug(num); // => example.c:26: num = 1 idebug(num, str); // => example.c:29: // num = 1 // str = hello idebug_raw("The answer is", answer()); // => example.c:34: The answer is 42 return 0; }
Just include debug.h in your file.
- Requires C11 support (uses
_Generic). Consider using the flag-std=c11when compiling. - Literal chars have type
int, so you have to cast them tocharto print them as actual chars:
debug_raw("Find the", (char)'X'); // => Find the X
For quick debugging, include the header right where you need it:
void function(void) { ... #include "debug.h" debug(var); // => var = XXX ... }
To remove quickly all debugging output, define NDEBUG before the header inclusion:
#define NDEBUG #include "debug.h" ... debug(var); // Doesn't print anything ...