Conditional characters do not work

I have a class library containing the following code snippet:

#if (DEBUG && CLOUD)
    return "DEBUG && CLOUD";
#elif (DEBUG && !CLOUD)
    return "DEBUG";
#else
    return "Release";
#endif

When I reference this library in my application, I only get DEBUG or Release as a return, even if CLOUD is defined.

+4
source share
2 answers

The behavior is so strange, so I switched to the solution properties on the configuration properties tab. I am shocked at what Visual Studio does.

enter image description here

+1
source

Case No. 1:

#define DEBUG 1
#define CLOUD 1

-> return "DEBUG && CLOUD";

Case No. 2:

#define DEBUG
#define CLOUD

-> return "Release";

In this example, you can find out what #if (cond)evaluates the numerical condition.

If you want to check only the definition, you must:

#if defined DEBUG && defined CLOUD
+1
source

All Articles