Hello,
I'm using Keil uVision V5.24.2.0 with ARM Compiler V5.06 update 5 (build 528). Initially, compiler optimization level was set to 1.
With this level, I found that the address assigned to a pointer changed, without any modification done by the code. To avoid this I reduced the optimization level to 0 and pointer address remained the same throughout and system reset, didn't occur.
Kindly, help me understand why would compiler optimization effect in such a way?
Here, is what I found www.keil.com/.../armcc_chr1359124221739.htm
Thank you in advance.
Changed during program execution? From what to what?
A pointer could be held in a register rather than a RAM variable when the compiler deems it more efficient to do so.
Show context where this is a problem, or how to replicate your situation.
Look at a disassembly of the code. The compiler can reorder code execution and remove code that doesn't do anything, or isn't run. One C line may have multiple assembler lines. Local variables may be held in registers or on the stack.
Thank you for replying.
Turns out it wasn't due to compiler but part of an API used was overwriting the memory location. When compiler optimization was reduced these memory locations were distant and hence there was no corruption for that address saved in the pointer. But the issue was in the code.
Regards, Tejeshwar
char c; char str[] = "4E"; sscanf(str, "%x", &c); // this type of thing frequently bites people