Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C / C++ : Portable way to detect debug / release?

Tags:

Is there a standardized (e.g. implemented by all major compilers) #define that will allow me to distinguish between debug and release builds?

like image 718
sivabudh Avatar asked Feb 12 '10 02:02

sivabudh


People also ask

How do I know if exe is debug or Release?

dll or .exe). From the Build menu, select Configuration Manager, then select Debug or Release. Or On the toolbar, choose either Debug or Release from the Solution Configurations list. The code which is written inside the #if debug will be executed only if the code is running inside the debug mode.

What is difference between release and debug mode?

By default, Debug includes debug information in the compiled files (allowing easy debugging) while Release usually has optimizations enabled. As far as conditional compilation goes, they each define different symbols that can be checked in your program, but they are language-specific macros.

What is the difference between debug mode and release mode in Visual Studio?

Visual Studio projects have separate release and debug configurations for your program. You build the debug version for debugging and the release version for the final release distribution. In debug configuration, your program compiles with full symbolic debug information and no optimization.


1 Answers

if believe

 #ifdef NDEBUG   // nondebug  #else   // debug code  #endif 

is the most portable.

But no compiler knows whether you are compiling debug or release, so this isn't automatic. But this one is used by assert.h in the c-runtime, so it's quite common. Visual Studio will set it, and I'm sure most other IDE's will as well.

like image 167
John Knoeller Avatar answered Sep 19 '22 07:09

John Knoeller