Software Technology Tips

At times it is possible that some operations work fine in Debug mode but not in Release mode and vice-versa.
 
Here are the some of the common errors that lead us to the above problem.
 
1. In general, the default value of an uninitialzed variable is garbage in Debug  and zero in Release .
 
   So, the following code works fine in Debug and not in Release .
 
            int enabled;
            if( enabled )
                DoSomeThing();
 
   So, Please initialise when a variable is declared.
2. One of the main difference in Debug and Release is Optimization.
 
         We can set this from Properties -> C/C++ -> Optimization.
 
         By default, optimization is turned off in the Debug configuration of a Visual C++ program and turned on in the Release configuration.
        Sometimes, however, a bug may appear only in an optimized version of a program. In that case, we must debug the optimized code.
 
Here are some techniques to test the application
            - Set the mode Debug and Optimization level is should be same as Release and now run the application.
            - Set the Release mode and change the Optimization level and run the application.
 
3.  Check the _DEBUG macro in the code. where it is used and How it is used.
          Look for any code that is inside of a "#ifdef _DEBUG" wrapper that might be needed in the Release version.
 
4.  Sometimes Warnings are important.
 
        When starting a project turn the warning level to "Level 3" or "Level 4" and  make sure the code compiles with minimal or no warnings.
5.  Don't Remove Needed Code in Release
 
      There are several macros that are commonly used that are completely removed when you compile in release mode.
      For example ASSERT macros and TRACE macros are quietly removed in Release builds. Any code that may be required,
      which was to be executed in an ASSERT or TRACE command will also be removed.
 
6.  Make the Debug mode more like Release
 
      Make the Debug mode more likely Release mode and Reproduce the problem in Debug mode.
      The main difference is _DEBUG macro is defined in Debug and NDEBUG macro is defined in Release.
      So, define NDEBUG in Debug instead of _DEBUG.
 
7. Generally, we can debug the code in Debug but not in Release.
 
       But we can also debug the code in Release by setting "Generate Debug Info"  in Project Properties page -> Link -> Generate Debug Info


Related Tags:

VC++, Debug

Author: Manjunath G

VC++

Let us Connect!

iso 9001 QA25 Red Herring STPI D&B Fastest Growing SME 2013 Award zinnov Nasscom

copyright (c) Mindfire Solutions 2007-2014. Login