FIX: Debugger Sees Only One Variable of Two with Same Name

Last reviewed: September 19, 1997
Article ID: Q155160
The information in this article applies to:
  • The integrated debugger included with: - Microsoft Visual C++, 32-bit Edition, version 4.2

SYMPTOMS

If there are two global scope variables of the same name in a project, only one symbol appears to exist when viewed in the debugger. The correct value is displayed for one of the symbols. All other symbols with the same name are displayed with that same value.

RESOLUTION

The two resolutions are:

  • Don’t use the same name for variables of global scope in different files.
  • Link with /pdb:none.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug was corrected in Visual C++ version 5.0.

MORE INFORMATION

For example, in the sample code below, the debugger shows the same value for the two variables, "i" in main.cpp and "i" in Func1.cpp. To watch the two variables in the same Watch window, use the context operator. Add the following two expressions in the Watch window:

   {,main.cpp,}i
   {,Func1.cpp,}i

Single-step through the code and notice that even though the two variables actually contain different values at all times, they are always displayed with the same value--the value of "i" in Main.cpp.

Sample Code

   // file main.cpp
   // Compile options needed: /Zi
   // main.cpp

   void Func1(int);

   int i=1;

   int main()
   {
       i = 200;

       Func1 (i);

       return 0;
   }
   // end of file main.cpp


   // file Func1.cpp
   // Compile options needed: none
   // Func1.cpp

   #include <stdio.h>

   float i=2.0f;

   void Func1(int n)
   {
       printf("\n n= %d",n);
       i = float(n+2);
       printf("\n hPf= %f", i);
   }

   // end of file Func1.cpp


Additional query words: 10.20
Keywords : CLIss TlsMisc vcbuglist420 vcfixlist500 kbprg kbtool
Version : 4.2
Platform : NT WINDOWS
Issue type : kbbug
Solution Type : kbfix


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 19, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.