Question: During debug mode or while I am doing testing, I need to print lots of various information, so i use this method:

```
#ifdef TESTING
// code with lots of debugging info
#else
// clean code only
#endif // TESTING`

```

Is this a good method, or is there any other simple and elegant method ?

But this way, I am repeating the same code in two places and if anything is to be changed later on in the code, I have to do it in both places, which is time consuming and error prone.

Thanks.

I am using MS Visual Studio.

Answer: 
Use a define like that on include headers

```
#ifdef  TESTING
#define DEBUG_INFOS(_X_) CallYourDebugFunction(_X_ )
#else
#define DEBUG_INFOS(_X_) ((void)0)
#endif

```

and then use only this on your code

```
...
DEBUG_INFOS("infos what ever");
RestOfWork();
...

```

You can also use and search for the **ASSERT** and **TRACE** macros and use the **DebugView** from sysinternals to read the output real time from trace, or track problems with the ASSERT. ASSERT and TRACE do similar work, and you can get ideas from them.

comments: I use the TESTING declare, because I see that on the question.
I'm writing for embedded systems in C. 
In my programs I'm using following macros:

```

#define _L  log_stamp(__FILE__, __LINE__)

#define _LS(a)  log_string(a)

#define _LI(a)  log_long(a)

#define _LA(a,l)  log_array(a,l)

#define _LH(a)  log_hex(a)

#define _LC(a)  log_char(a)

#define ASSERT(con) log_assert(__FILE__, __LINE__, con)

```

When I'm making release version, I simply switch off #define DEBUG directive and all macros become empty. 
Note that it doesn't consume any CPU cycles and memory in release version.
Macros are the only way to save to log information: where the logging was done 
(file and line number).

If I need this information I use:
`_L;_LS("this is a log message number ");_LI(5);`

otherwise without `_L` directive.