Search code examples
c#conditional-compilationundef

Is it really necessary to explicitly define "undefine" even when the define is commented out?


I was having some problems with this code executing:

#if TRACE
            dbgLog = new LogInfo( "PlatypusCE" );
#endif   

This was occurring even though "TRACE" was commented out above, right after a large block of general comments:

//#define TRACE

Once I added this below it:

#undef TRACE

...so that it is:

//#define TRACE
#undef TRACE

...it works as desired, though (the "#if TRACE" code doesn't execute).

Is it really necessary to undefine something that has not been defined (is commented out)? It seems bizarro.


Solution

  • By default, in the profiles Debug and Release, Visual Studio will define the TRACE constant. You can change this behavior in the project settings (in the Build tab). The DEBUG constant is similar, active by default in the Debug profile (but not Release).