Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


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.

  • You cannot reply to this topic
8 replies to this topic

#1 TiagoCosta   Crossbones+   -  Reputation: 2339

Like
0Likes
Like

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

Sponsor:

#2 bbobak   Members   -  Reputation: 109

Like
0Likes
Like

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?

#3 Hodgman   Moderators   -  Reputation: 30950

Like
0Likes
Like

Posted 15 June 2011 - 07:19 PM

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

#4 Servant of the Lord   Crossbones+   -  Reputation: 20283

Like
0Likes
Like

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' 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 - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#5 TiagoCosta   Crossbones+   -  Reputation: 2339

Like
0Likes
Like

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

#6 Rene Z   Members   -  Reputation: 522

Like
0Likes
Like

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.

#7 forsandifs   Members   -  Reputation: 154

Like
1Likes
Like

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.

#8 TiagoCosta   Crossbones+   -  Reputation: 2339

Like
0Likes
Like

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

#9 Adam_42   Crossbones+   -  Reputation: 2562

Like
0Likes
Like

Posted 16 June 2011 - 07:40 AM

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.




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.



PARTNERS