“DEBUG” is used in every case of the #if compiler directive that I’ve seen. Can I use “RELEASE” in the same way to exclude code from debug mode compilation that I don’t want to run? The code I want to enclose with this block sends out a lot of emails, which I don’t want to send out by accident when testing.
Asked by Brian Sullivan
Although RELEASE isn’t defined, you can use it.
#if (!DEBUG) ... #endif
Answered by M4N
No, unless you put in some effort.
The crucial thing is to understand what DEBUG is, which is a kind of defined constant that the compiler can verify against.
Three things can be found in the project properties, under the Build tab:
There is no such checkbox, nor constant/symbol pre-defined that has the name RELEASE.
Before doing so, make sure the project configuration is set to Release-mode, as these adjustments are per configuration.
So, unless you include that in the text field, #if RELEASE will not generate any code in any configuration.
Answered by Lasse V. Karlsen
There is a DEBUG specified constant (automatically defined by Visual Studio) in debug mode, but no such constant is defined in release mode. Under build, look at your project’s settings.
When you select [Define DEBUG constant] from Project -> Build, it’s the same as including #define DEBUG at the top of every file.
To define a RELEASE constant for the release configuration, navigate to:
Answered by Pop Catalin
#if RELEASE does not work on my VS installation (VS 2008). You might, however, just use #if! DEBUG
#if !DEBUG SendTediousEmail() #endif
Answered by JaredPar
That’s something I’ve never seen before…but I have seen:
#if (DEBUG == FALSE)
Is that what you’re looking for?
Answered by Pete H.
Post is based on https://stackoverflow.com/questions/507704/will-if-release-work-like-if-debug-does-in-c