2 ms·
Also compiling with heavy optimization (such as -O3) can blow a variable out of the stack and into a register that can quickly get reused, or can also inline fu
by pvarangot 15y ago
Also compiling with heavy optimization (such as -O3) can blow a variable out of the stack and into a register that can quickly get reused, or can also inline functions. Both of this can break the perceived predictability.
In fact, here on my computer, your code example behaves differently when compiled with gcc default optimizations and when using -O3.
[peter@laptop ~]$ gcc test.c -o test
[...] warnings
[peter@laptop ~]$ ./test
43
[peter@laptop ~]$ gcc -O3 test.c -o test
[...] warnings
[peter@laptop ~]$ ./test
42
I'm inclined to believe in this case this is happening due to function inlining, but I haven't checked the assembly.
Edit: My post refers to the last version of your code, with the int i = *f; line in it.