We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I used LPC1765 in the system, the program is as follows:
#include<math.h>
...
int main(void)
{ ...
float a,b,c;
b = 3.1;
a = log(b);
c = sin(a);
}
the program is compiled and linked with no error, but "a" and "c" can't get the correct value. who could help me? thanks a lot!
In addition, the develop tool is MDK4.22
If subsequent code does not explicitly use these variables, the compiler is free to remove them from the generated code. How does you disassembly view look like?
"a" and "c" can't get the correct value
And you know that ... how?
Describing what did not happen is almost never a useful way of reporting a problem. You need to describe what happened instead, and why you think that's not what should have happened.
This comes up time and time again. Somehow everyone assumes that the source code is traceable 100% in the debugger. Have no-one heard about compiler optimization? And the things it does to ease of debugging?
I debug the program in simulation mode, and excecute the program step by step, thus "a" and "c" can be see from the watch windows.
I debug the program in simulation mode, and excecute the program step by step, thus "a" and "c" can be see from the watch windows. I know the compiler will do optimization, but "a" should show the correct value while simulation.
I know the compiler will do optimization, but "a" should show the correct value while simulation.
It probably should. But it certainly will not. Not in all cases, anyway.
If the compiler knows that sin() and log() doesn't have any side effects, then it could figure out that c isn't used, so no need to call sin(), and then a isn't used so no need to call log(). And then b isn't used, so no need to allocate such a variable either.
Next thing is that the debugger isn't always managing to correctly display variable values.
http://www.keil.com/forum/19850