Sign in to follow this  

UINT var always 0

This topic is 2407 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In my program I'm using UINT vars.
[code]
UINT x = 0;

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

The program seems to work correctly, but when I debug my program the value of x is always 0...
Even if I write this:
[code]
x = 20;
[/code]
x is always = 0.

Any idea of what might be causing this??

Share this post


Link to post
Share on other sites
perhaps you are inspecting another x, or shadowing one.

[code]
int x = 0;

{
int x = 0;

++x;
}
[/code]

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

Share this post


Link to post
Share on other sites
[quote name='bbobak' timestamp='1308186237' post='4823876']
more context would be helpful. If you std::cout (or printf in C) x, does it show the correct value?
[/quote]

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:
[code]
//k = 7
UINT mN = pow(2.0f, k) - 1;
UINT mM = (mN + 1)/4;
[/code]

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...

Share this post


Link to post
Share on other sites
[quote name='Hodgman' timestamp='1308187153' post='4823878']
Are you debugging a release build?
[/quote]

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.

Share this post


Link to post
Share on other sites
[quote name='TiagoCosta' timestamp='1308213297' post='4823986']mM get a weird value like -858993460, but everything is rendered correctly and if I output mM the value is correct...[/quote]

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.

Share this post


Link to post
Share on other sites
[quote name='Rene Z' timestamp='1308214257' post='4823994']
[quote name='Hodgman' timestamp='1308187153' post='4823878']
Are you debugging a release build?
[/quote]

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...


[quote name='forsandifs' timestamp='1308215566' post='4823999']
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]

(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:

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this