|
To be honest, it should be straight forward but I took me a while to figure it out.
I wanted to mark certain lines in the code such that I can easily enable/disable it. So here it is:
// set to 1 to enable timing and output
#if 0
#define TIMING
#define OUTPUT
#else
#define TIMING / ## /
#define OUTPUT / ## /
#endif
...
TIMING startTimer();
...
TIMING stopTimer();
...
when #define TIMING / ## / is used then TIMING is replaced with //. Thus the entire line is commented and therefore disabled. This way i can easily turn on/off several debugging facilities.
The ## in the macro definition means that the previous and successive pieces of text are concatenated. So TIMING myCode; results in // myCode;. We cannot use #define TIMING // because the // won’t be parsed as the replacement string, it will be parsed as the comment literal.
This is a simple but handy technique.
|