I want to make a debugging subsystem like in the following example:
Code:
#include <stdio.h>
/*
to be put in some general debug.h in the way:
#define MAIN_DEBUG
#define SOME_OTHER_FUNCTION_NAME_DEBUG
*/
#define REAL_DEBUG(msg) \
do { \
printf ("debug message " msg "\n"); \
} while(0)
int main (void)
{
/*Here I want to check if macros "__FUNCTION__" + "_DEBUG" defined.*/
#ifdef MAIN_DEBUG
#define DEBUG(x) REAL_DEBUG(x)
#else
#define DEBUG(X)
#endif
DEBUG("test");
}
The thing is that I want to be able to disable all debugging output in one function by just commenting out one line in some header file.
The questions are:
1. Can I somehow write just one line in the beginning of each function expanding to
Code:
#ifdef MAIN_DEBUG
#define DEBUG(x) REAL_DEBUG(x)
#else
#define DEBUG(X)
#endif
?
2. Can it be automated so I don't have to write the function name explicitly, i.e. not
but something like
Code:
#ifdef __FUNCTION__ + "_DEBUG"
?