Except for the often-frowned-upon way of including #ifdef's in a .c file, there are two ways to include debug code in a program:
1. In xxx.h:
Code:
#ifdef DEBUG
void debugprint(const char *s);
#else
static inline debugprint(const char *dummy) {}
#endif
And in xxx.c:
Code:
int somefunction(...)
{
...
debugprint("...debug info...");
...
}
2. In xxx.c:
Code:
int somefunction(...)
{
...
if (DEBUG)
debugprint("...debug info...");
...
}
The second method can test all possible execution paths of a program during compile time but the code is littered with "if (DEBUG)". DEBUG is defined in a command-line compiler option (-D). What one is better? Thank you.