whats going on??????
-
This is a C question. I have the following for loop in my program: for(double i=0.0; i<360.0; i+=3.0/10.0) { //do stuff } everything works fine, but I changed it to this because I need to generalize the code later on: double angle=3.0/10.0; for(double i=0.0; i<360.0; i+=angle) { //do stuff } and now the program crashes when I run it. I don't see the difference between either of those two. And "no" there is nothing complicated in the for loop such as changing the value of angle part way through while I'm running through the loop. So what is going on here????????
-
This is a C question. I have the following for loop in my program: for(double i=0.0; i<360.0; i+=3.0/10.0) { //do stuff } everything works fine, but I changed it to this because I need to generalize the code later on: double angle=3.0/10.0; for(double i=0.0; i<360.0; i+=angle) { //do stuff } and now the program crashes when I run it. I don't see the difference between either of those two. And "no" there is nothing complicated in the for loop such as changing the value of angle part way through while I'm running through the loop. So what is going on here????????
I tried it and didn't see any crash!
double angle=3.0/10.0; for(double i=0.0; i<360.0; i+=angle) { //do stuff TRACE1("%f", i); }
Look at the reason of the error, it is an exception error? did you pass some invalid value to a math function (most of them will return NaN value)? The other thing I can say, debug (F9, F10, F11). "Dirty hands lead to important discovery..." - Thomas Edison -
This is a C question. I have the following for loop in my program: for(double i=0.0; i<360.0; i+=3.0/10.0) { //do stuff } everything works fine, but I changed it to this because I need to generalize the code later on: double angle=3.0/10.0; for(double i=0.0; i<360.0; i+=angle) { //do stuff } and now the program crashes when I run it. I don't see the difference between either of those two. And "no" there is nothing complicated in the for loop such as changing the value of angle part way through while I'm running through the loop. So what is going on here????????
A significative difference is that in the latter case, the increment value is stored in the stack (at least in debug mode), while in the former it is a constant value directly fed to the
ADD
assembly instruction. So, I'd bet for your program somehow corrupting he stack (maybe writing out of bonds of some array?) Joaquín M López Muñoz Telefónica, Investigación y Desarrollo -
A significative difference is that in the latter case, the increment value is stored in the stack (at least in debug mode), while in the former it is a constant value directly fed to the
ADD
assembly instruction. So, I'd bet for your program somehow corrupting he stack (maybe writing out of bonds of some array?) Joaquín M López Muñoz Telefónica, Investigación y Desarrollo -
To make sure, put something like this at the beginning of your
for
:for(double i=0.0; i<360.0; i+=angle)
{
assert(angle==3.0/10.0);
...
}if the
assert
fires, then it is almost sure you're corrupting the stack. Check your indices, do a step-by-step run examining the exact moment whenangle
changes, etc. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo