Public Group

# same code behaves differently after recompilation

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

## Recommended Posts

In my code, I have a section

void IncineratorFire::ChangeAnimAndody(Uint32 newframe){   // some stuff removed   const double top = -16 * newframe;   // other stuff removed}

(Uint32 is defined in SDL)

Anyway, for months, this has always given the expected result. However, this evening I updated Box2d to the latest version, and suddenly this code, in a completely unrelated section of the program, stopped working. It took me a while to track down the bug since I initially suspected Box2d, but I eventually discovered that top now had the value 4.29497e+009, instead of the expected -64.

My theory is that the -16 is now being casted to an unsigned int, when before, newframe was casted to a signed int. I fixed the bug by changing it to -16.0, thus making it a double, but I'm still mystified why it happened in the first place.

Why would changing stuff in a completely unrelated part of the program suddenly make this statement change its meaning? And why now, instead of every time I update Box2d, or whatever? What the heck is going on?

[Edited by - Storyyeller on August 21, 2010 11:35:56 PM]

##### Share on other sites
Sounds to me like you're overwriting memory you shouldn't be. The bad thing about these errors is that they can be there for a long time, overwriting something not noticeable/important, and then you add some new variables (new version of box2d) and all the sudden you're overwriting important things. Good luck finding it though as it could be pretty much anywhere in your code. Also remember that just because changing that int to a double fixed it, doesn't mean its gone. It's still there, just overwriting something non-critical/noticeable again.

##### Share on other sites
How can I be overwriting memory? I'm dealing with ints, not pointers!

##### Share on other sites
Given " -16 * newframe " and that newframe is an unsigned integer, the compiler had to match types to perform the multiplication. It converted -16 to an unsigned integer (since you didn't give it a type), performed the multiplication and converted the result to double.

The question should be: why did it work as it did in the past?

##### Share on other sites
Exactly. It's not really surprising that -16 would be casted to an unsigned int. What is surprising is that it worked before, and randomly changed for no apparent reason.

1. 1
2. 2
3. 3
Rutin
13
4. 4
5. 5

• 26
• 10
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633696
• Total Posts
3013397
×