Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatic #defines according to Debug/Release config in Visual Studio

I have debug output in my program like this:

#define DEBUG ... #ifdef DEBUG     std::cout << "[RE_words] " << m_re << std::endl; #endif 

and DEBUG is defined in my program manually. I always comment out the line when I make a release version. In Visual Studio, there are also Configurations for Debug vs Release versions which handle the commandline etc. used for compiling. Can I also use the Configuration "Debug" to automatically define DEBUG to the compiler? How?

like image 430
Felix Dombek Avatar asked Jan 05 '11 13:01

Felix Dombek


People also ask

What does it mean when it says automatic?

If a machine or device does something automatically, it does it independently, without human control: The camera adjusts the shutter speed automatically.

What is the synonym for automatic?

Some common synonyms of automatic are impulsive, instinctive, mechanical, and spontaneous.

Is automatically a real word?

without volition or from force of habit; mechanically: Whenever I hear that song, I automatically think of my dad. by a device or process requiring no human intervention: The switch can be operated automatically or manually. in a manner independent of a decision or action:Your membership will be renewed automatically.

What is the meaning of automatic machine?

Definition of automatic machine : a machine or machine tool (such as a spinning machine or lathe) that after once being set operates automatically except for applying the power, lubricating, supplying material, and shutting off the power.


1 Answers

The Visual Studio automatically defines _DEBUG symbol for Debug builds (and NDEBUG for non-debug builds).

Another way to do this is to go to the project settings -> configuration properties -> C/C++ -> preprocessor, and edit the preprocessor definitions manually.

See also:
This answer explains the differences between _DEBUG and NDEBUG in more detail.
This answer explains the purpose of the NDEBUG symbol and whether or not is it defined by the standard.

like image 96
Jan Holecek Avatar answered Sep 20 '22 10:09

Jan Holecek