J.K. Becker said:
Ok, after a make clean -- makeg (again) this is what happens:
dEdp gets a value in line 1, if the program continues to line 2 dEdp
changes. So the calculation is done correctly, but the value changes for
some reason. And most of the time it changes back to the right value
after line 3...
I have put the function into an older version of the program, it does
more or less the same but dEdp does not change back to the original
value after completing with line 3....
I have no idea, but I wish I would get a Euro for every time I did make,
I would be stinking rich by now!
1- dEdp = ( ( gvector.x / gvector.y ) + ( gvector.y / gvector.x ) ) / lenP;
2- Fx = un.x * dEdp;
3- Fy = un.y * dEdp;
Jens
Try declaring "dedp" as either static or volatile.
These two modifiers will help prevent variables being optimized-out.
I've seen my debugger change values of two variables when only one
has been changed (the compiler uses the same register later on..).
Also, have you considered rewriting the arithmetic to:
1. Removed fixed calculations & variables out of loops?
2. Changing multiplication to repetitive addition?
I highly suggest you use print to a debug file, with statements
like:
fprintf(debug_file, "At Line %d: dEdp == %f, un.x == %f\n",
__LINE__, dEdp, un.x);
Insert this kind of print statement after each line of calculation.
This will slow down the program, but you will get a detailed
analysis in the debug file.
--
Thomas Matthews
C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq:
http://www.parashift.com/c++-faq-lite
C Faq:
http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book