#include"debug.h"intanswer(void) {
return42;
}
intmain(void) {
intnum=1;
char*str="hello";
debug(num);
// => num = 1debug(num, str, answer());
// => num = 1// str = hello// answer() = 42debug_raw("counting:", 1, -2, 3+0.4);
// => counting: 1 -2 3.4debug_raw(str, "world!");
// => hello world!idebug(num);
// => example.c:26: num = 1idebug(num, str);
// => example.c:29:// num = 1// str = helloidebug_raw("The answer is", answer());
// => example.c:34: The answer is 42return0;
}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 XFor quick debugging, include the header right where you need it:
voidfunction(void) {
...
#include"debug.h"debug(var); // => var = XXX
...
}To remove quickly all debugging output, define NDEBUG before the header inclusion:
#defineNDEBUG#include"debug.h"
...
debug(var); // Doesn't print anything
...