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:
1
2
3
4
5
6
7
8
9
10
11
12
13
| // set to 1 to enable timing and output
#if 0
#define TIMING
#define OUTPUT
#else
#define TIMING / ## /
#define OUTPUT / ## /
#endif
...
TIMING startTimer();
...
TIMING stopTimer();
... |
// 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
is used then
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
results in
. We cannot use
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.
|