• FEATURED

View more

View more

View more

Image of the Day Submit

IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

UINT var always 0

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

8 replies to this topic

#1TiagoCosta  Members

Posted 15 June 2011 - 06:13 PM

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

#2bbobak  Members

Posted 15 June 2011 - 07:03 PM

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?

#3Hodgman  Moderators

Posted 15 June 2011 - 07:19 PM

Are you debugging a release build?
If not, post the code.

#4Servant of the Lord  Members

Posted 15 June 2011 - 07:43 PM

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.
It's perfectly fine to abbreviate my username to 'Servant' or 'SotL' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames -

#5TiagoCosta  Members

Posted 16 June 2011 - 02:34 AM

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

#6Rene Z  Members

Posted 16 June 2011 - 02:50 AM

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.

#7forsandifs  Members

Posted 16 June 2011 - 03:12 AM

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.

#8TiagoCosta  Members

Posted 16 June 2011 - 03:57 AM

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.

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