UINT var always 0

Started by
7 comments, last by Adam_42 12 years, 10 months ago
In my program I'm using UINT vars.

UINT x = 0;

[a loop]
x++;
[end of the loop]


The program seems to work correctly, but when I debug my program the value of x is always 0...
Even if I write this:

x = 20;

x is always = 0.

Any idea of what might be causing this??
Advertisement
perhaps you are inspecting another x, or shadowing one.


int x = 0;

{
int x = 0;

++x;
}


more context would be helpful. If you std::cout (or printf in C) x, does it show the correct value?
Are you debugging a release build?
If not, post the code.
Which debugger are you using? Sometimes when running gdb from QtCreator, it irritatingly doesn't update the value of the variables in the debugging window, despite them changing in the actual program.

more context would be helpful. If you std::cout (or printf in C) x, does it show the correct value?


yes, it shows the correct value.

Well there is not need ti show my code, because apparently everything has incorrect values... but it works correctly so I'm pretty sure there is a problem with the debugger.

I'm using Visual Studio 2010 and I'm pretty sure that I never messed with debugger configurations...

A bit of code:

//k = 7
UINT mN = pow(2.0f, k) - 1;
UINT mM = (mN + 1)/4;


mN gets the correct value (15)
mM get a weird value like -858993460, but everything is rendered correctly and if I output mM the value is correct...

P.S. Another problem that I usually have with Visual Studio 2010 is really slow automatic underlying of code mistakes... I thought that Visual Studio was one of the best IDEs...

Are you debugging a release build?


I'll ask that question too, because it sounds like you're doing just that. Debugging release builds isn't pretty, try a debug build instead.
mM get a weird value like -858993460, but everything is rendered correctly and if I output mM the value is correct...


This suggests to me that your breakpoint is not far enough along in your code. If I'm correct try setting the breakpoint to the next line after UINT mM = (mN + 1)/4; . Then you should see mM take the correct value.

[quote name='Hodgman' timestamp='1308187153' post='4823878']
Are you debugging a release build?


I'll ask that question too, because it sounds like you're doing just that. Debugging release builds isn't pretty, try a debug build instead.
[/quote]
I'm debugging a debug version...



This suggests to me that your breakpoint is not far enough along in your code. If I'm correct try setting the breakpoint to the next line after UINT mM = (mN + 1)/4; . Then you should see mM take the correct value.


(This is not the first time I'm debugging a program :rolleyes:) I was putting the breakpoints in the right places... (but thank you for remembering anyway =])

I fixed this problem by rebuilding my entire program....

NOTE TO SELF: Rebuild the program when a weird bug is found.

Anyway Thank you to everyone that tried to help :lol:
If your debug and release builds output their intermediate files to the same folder, that can mess up dependency checking when you switch between the two.

This topic is closed to new replies.

Advertisement