Microsoft KB Archive/115347

= PRB: Debugger Cannot Watch Global Constants in C++ Programs =

Article ID: 115347

Article Last Modified on 8/16/2005

-

APPLIES TO

 Microsoft Visual Workbench for Windows, when used with:  Microsoft Visual C++ 1.0 Professional Edition

 Microsoft Visual C++ 5.0 Learning Edition

 Microsoft Visual C++ 5.0 Enterprise Edition

 Microsoft Visual C++ 2.1</li></ul>

 Microsoft Visual C++ 4.0 Professional Edition</li></ul>

 Microsoft Visual C++ 5.0 Professional Edition</li></ul>

 Microsoft CodeView 4.0</li></ul>

 Microsoft CodeView 4.01</li></ul>

 Microsoft CodeView 4.1</li></ul>

 Microsoft CodeView 4.0</li></ul>

 Microsoft CodeView 4.01</li></ul>

 Microsoft CodeView 4.1</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q115347

<div class="symptoms_section">

SYMPTOMS
On page 17 in chapter 2 of the C++ Tutorial included in Microsoft C/C++, version 7.0 and Visual C++, version 1.0, it states:

"Constants declared with const have an advantage over those defined by #define in that they are accessible to a symbolic debugger, making debugging easier."

However, when global constants are used in a C++ program, they cannot be watched in a local or watch window with CodeView or the Integrated (IDE) Debugger in Visual C++.

<div class="resolution_section">

RESOLUTION
The above behavior is by design in the products listed above. In these versions, with the exception of CodeView 4.25 for Win32S, only local constants are accessible to CodeView and the Visual C++ IDE debugger.

<div class="cause_section">

CAUSE
In Microsoft C++, storage of global constants is optimized for the purpose of saving space, therefore no debug information is generated.

<div class="moreinformation_section">

MORE INFORMATION
When debugging the following C++ sample program with CodeView, attempting to watch the global const a yields the following error:

A = CXX0030: Error: expression cannot be evaluated

Attempting to watch A using the Visual C++ for Windows version 1.0 or the Visual C++ 32-bit Edition version 1.0 or 2.1 IDE Debugger yields a dialog box with the following text:

Cannot watch 'A'.

Attempting to watch A using the Visual C++ 32-bit Edition version 4.0 IDE Debugger produces the following in the Watch window:

A = CXX0017: Error: symbol "A" not found

Sample Code
/* Compile options needed: /Zi /Od */

const int A=100; void main {     int dummy=0; dummy++; }

Additional query words: utilities

Keywords: kbbug kbide kbdebug kbprb KB115347

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.