Hello experts, I'm a beginner of embedded system development.
I have question.about difference of two code.
at first, suppose there is function like
int SomeFunction(void) {
......
return (some integer);
}
And using this function return value like these
retval = SomeFunction();
if (retval == {some Variable}) {
. . .
....
former one doesn't make any problem, but when i used like latter one.. some times, retval is not correct and some strange value remains on r0 register...;
I don't know what is problem on latter one exactly...;
Could explain what is the problem of these?
Thank you very much for reading this..... though it is written by pool english...
I don't know what's happening about the bug you're getting, but I would like to point out that a (volatile int) cast does nothing more that just (int) does on its own. volatile applies to accessing a location, not a value. If you declared a function as pure using a pragma the compiler would be entitled to only call it once for the same parameters even if you put (volatile int) before each call.
The only really useful use of volatile in a cast is in things like
*(volatile int *)intptr
The whole bunch of linux code is written alluding to "volatile" where it just shouldn't rely on this behaviour.
Many problems, yes _many_, arise this way.
Perhaps, I'd recommend +never+ using optimisation options when you feel that the control flow may in some or other way be affected.
Normally, GCC outputs ingenious code, but when you force, the compiler is also forced to think otherwise making you code unpredictable.
And such errors are really hard to find sometimes.
So, any code relying on "volatile" or other compiler "hints" is intrinsically +buggy+. Do try avoiding them altogether.
View all questions in Embedded forum