The developer studio integrated debugger may display incorrect values for the local variables in an application when the application is compiled with optimizations on

Article translations Article translations
Article ID: 100773 - View products that this article applies to.
This article was previously published under Q100773
This article has been archived. It is offered "as is" and will no longer be updated.
Expand all | Collapse all

On This Page

SYMPTOMS

The Developer Studio integrated debugger may display incorrect values for the local variables in an application. This can occur when the application being debugged was compiled with optimizations on.

RESOLUTION

During the debugging process for your application, specify the /Od compiler option switch to disable optimizations.

MORE INFORMATION

The C/C++ compilers mentioned above make ample use of registers to store local variables. This is particularly true when optimizations are turned on. Therefore, information regarding local variable storage is not always available to the debugger.

The following code example demonstrates this behavior. If you compile this code with optimizations disabled (specify the /Od compiler option switch), the values of the local variables in the func1() function are correctly displayed after the code calls the func2() function. However, if you compile the code with optimizations (specify the /Ox compiler option switch), the values of the same local variables do not display correctly until the code executes the return statement from func2().

Sample Code

   /*
    * Compile options needed: /Ox
    */ 

   void func2(int *arg1, int *arg2, int *arg3)
   {
      *arg1 = *arg2 = *arg3 = 5;
   }

   int func1(int arg1)
   {
      int local1, local2;

      func2(&arg1, &local1, &local2);

      return arg1 + local1 + local2;

   }

   void main(void)
   {
      func1(1);
   }
				

Properties

Article ID: 100773 - Last Review: February 28, 2014 - Revision: 4.0
APPLIES TO
  • Microsoft Visual C++ 1.0 Professional Edition
  • Microsoft Visual C++ 2.0 Professional Edition
  • Microsoft Visual C++ 4.0 Standard Edition
  • Microsoft Visual C++ 5.0 Enterprise Edition
  • Microsoft Visual C++ 6.0 Enterprise Edition
  • Microsoft Visual C++ 5.0 Professional Edition
  • Microsoft Visual C++ 6.0 Professional Edition
  • Microsoft Visual C++, 32-bit Learning Edition 6.0
  • Microsoft Visual C++ .NET 2002 Standard Edition
  • Microsoft Visual C++ .NET 2003 Standard Edition
  • Microsoft Visual C++ 2005 Express Edition
Keywords: 
kbnosurvey kbarchive kbide kbdebug kbprb KB100773

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com