Incorrect value for Static variables with same name 
Author Message
 Incorrect value for Static variables with same name

I have a problem with the Visual C++ 6.0 de{*filter*} thats making me crazzy.
I have two (static) functions that contain the static variables with the
same name (see code below). When I debug these functions, the value of the
static variable is corect in the first function, but when I enter the second
function, the static variable in this function has the value of the static
variable in the first function.

The code below is a simple Win32 Console application to demonstrate the
problem. When I enter funtion1(), the value of iTest1 (e.g. in the Watch
window) is "1" after the instruction "iTest1 = 1;".
Next when I enter function2(), the value of iTest1 (e.g. in the Watch
window) is still "1", even after the instruction "iTest1 = 2;".

Even when I us "{function1,,}iTest1" and "{function2,,}iTest1" in the watch
window, the value is "1" for both expressions.

Can anyone tell me how I can solve this problem.

==============================================
#include "stdafx.h"
void function1( void );
void function2( void );

int main(int argc, char* argv[])
{
   function1();
   function2();
   return 0;

Quote:
}

void function1( void )
{
 static int iTest1;
 iTest1 = 1;

Quote:
}

void function2( void )
{
 static int iTest1;
 iTest1 = 2;
Quote:
}

==============================================


Sun, 05 Oct 2003 21:18:55 GMT  
 Incorrect value for Static variables with same name
Hello Peter,

I've just checked your program on my PC (Win2000 Professional SP1, VS60
SP5) - it works fine and de{*filter*} doesn't have similar problems.

Regards,
Vadim.


Quote:
> I have a problem with the Visual C++ 6.0 de{*filter*} thats making me crazzy.
> I have two (static) functions that contain the static variables with the
> same name (see code below). When I debug these functions, the value of the
> static variable is corect in the first function, but when I enter the
second
> function, the static variable in this function has the value of the static
> variable in the first function.

> The code below is a simple Win32 Console application to demonstrate the
> problem. When I enter funtion1(), the value of iTest1 (e.g. in the Watch
> window) is "1" after the instruction "iTest1 = 1;".
> Next when I enter function2(), the value of iTest1 (e.g. in the Watch
> window) is still "1", even after the instruction "iTest1 = 2;".

> Even when I us "{function1,,}iTest1" and "{function2,,}iTest1" in the
watch
> window, the value is "1" for both expressions.

> Can anyone tell me how I can solve this problem.

> ==============================================
> #include "stdafx.h"
> void function1( void );
> void function2( void );

> int main(int argc, char* argv[])
> {
>    function1();
>    function2();
>    return 0;
> }

> void function1( void )
> {
>  static int iTest1;
>  iTest1 = 1;
> }

> void function2( void )
> {
>  static int iTest1;
>  iTest1 = 2;
> }
> ==============================================



Mon, 06 Oct 2003 02:28:41 GMT  
 Incorrect value for Static variables with same name
Hello Vadim,

Thanks for the reaction. I did not yet have SP5 installed, so I downloaded
it (133MB !!) and tried again.
It did not help. I did one other thing which solved the problem but disabled
the "Edit and Continue"feature.

When  I  change the setting for "C/C++, general, Debug Info" form "Program
Database for Edit and Continue" into "Program Database", the de{*filter*} works
fine. The "Edit and Continue" feature is however very nice and I do not want
to turn it off, so I still have the problem.

Anyone know the solution ?

Best regards,
Peter


Quote:
> Hello Peter,

> I've just checked your program on my PC (Win2000 Professional SP1, VS60
> SP5) - it works fine and de{*filter*} doesn't have similar problems.

> Regards,
> Vadim.



> > I have a problem with the Visual C++ 6.0 de{*filter*} thats making me
crazzy.
> > I have two (static) functions that contain the static variables with the
> > same name (see code below). When I debug these functions, the value of
the
> > static variable is corect in the first function, but when I enter the
> second
> > function, the static variable in this function has the value of the
static
> > variable in the first function.

> > The code below is a simple Win32 Console application to demonstrate the
> > problem. When I enter funtion1(), the value of iTest1 (e.g. in the Watch
> > window) is "1" after the instruction "iTest1 = 1;".
> > Next when I enter function2(), the value of iTest1 (e.g. in the Watch
> > window) is still "1", even after the instruction "iTest1 = 2;".

> > Even when I us "{function1,,}iTest1" and "{function2,,}iTest1" in the
> watch
> > window, the value is "1" for both expressions.

> > Can anyone tell me how I can solve this problem.

> > ==============================================
> > #include "stdafx.h"
> > void function1( void );
> > void function2( void );

> > int main(int argc, char* argv[])
> > {
> >    function1();
> >    function2();
> >    return 0;
> > }

> > void function1( void )
> > {
> >  static int iTest1;
> >  iTest1 = 1;
> > }

> > void function2( void )
> > {
> >  static int iTest1;
> >  iTest1 = 2;
> > }
> > ==============================================



Tue, 07 Oct 2003 21:21:12 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Help - I need to set variable A = value held in variable named in variable B

2. Debugger shows incorrect global static variable structure

3. Global and static variables initial values...

4. static variables in exported class having different values between dll and exe

5. static variables in exported class having different values between dll and exe

6. How can get the element value out the XML when it has variable tag name

7. Native debugger shows incorrect values.

8. Return value incorrect?

9. incorrect value of expression in debug Watch window

10. sin and cos return incorrect values

11. sin and cosine return incorrect values..

12. Search incorrect name

 

 
Powered by phpBB® Forum Software