Say I have the following code snippet in c#
static const bool DO_PERFORMANCE_CODE = false; if (DO_PERFORMANCE_CODE) { // performance monitoring code goes here }
Will that code get removed by the compiler? This is the functionality I’d like. Basically I want to mimic the conditional compilation stuff in C#, but I want more configurations other than Release and Debug. If there is a better way of doing this, I’d be open to hearing it.
When you build in ‘debug’ the preprocessor variable DEBUG is defined. So, you can do this:
and it will be ignored by the compiler when you switch to Release mode.
Alternatively, you can define your own preprocessor variable if you don’t want to test in debug mode, making sure to ‘#define PERFORMANCE_TESTING’ when you want to test, and commenting it out when you don’t.