views:

613

answers:

2

For a C++ project that I'm developing in Visual Studio 2005, I would like to disable the TRACE output option while running the code in debug mode. I have searched the internet about how to achieve this, but no luck. Is this even easily achievable? If so, how? Thanks in advance.

Update #1:

#define  USETRACE  0
#if !USETRACE && DEBUG
    #undef TRACE
    #define TRACE(x)
#endif

I tried the above code in debug mode, near the very top of stdafx.h, but TRACE is still outputting to the debug output. It would be great if suggestions on what's wrong with my implementation are provided so that I can fix it. Thanks.

+2  A: 

It turns out there is a much simpler way to do this, set global variable afxTraceEnabled to false

afxTraceEnabled = false;

Reference

JaredPar
Forgot the undef line.
stanigator
I added the undef line in my macro in that situation. However, the TRACE statement is still working as undesired (printing to the debug output window). I put these lines in the precompiled header (stdafx.h). Is there anything significantly inappropriate by putting the instructions in the precompiled header? Thanks.
stanigator
@stanigator, no. I often put macros such as this at the top of stdafx.h to enusre it's applied globally.
JaredPar
@JaredPar: I've updated on my original post on what I tried to do. Cheers.
stanigator
@stanigator, found a better solution, see updated answer.
JaredPar
@JaredPar: the updated answer didn't work either.
stanigator
A: 

Used the difficult way first few times, this is what I end up doing:

#if USETRACE
    #define PRINT TRACE
#else
    #define PRINT
#endif
stanigator