2 ms·
> In a simplistic, pointers-are-integer model, these two functions are not equivalent, In reality two functions are never and can never been equivalent--they c
by titzer 6y ago
> In a simplistic, pointers-are-integer model, these two functions are not equivalent,
In reality two functions are never and can never been equivalent--they can only be observationally equivalent.
> you need to have to some sort of rule that...whose address is never taken can never be legally accessed by a pointer.
Such a "rule" does exist. If the above is a C program, said C program must have undefined behavior (read: other pointer bugs) to observe x's value.
Programs with pointer bugs can do insanely weird things because they break all the abstractions of programming language and expose the memory layout.
The point of the article is that compilers shouldn't try to exploit undefined behavior in pursuit of more performance. The fact that you can observe optimization means that abstractions of the languages are broken. C and C++ are essentially the only languages in existence where rampant observation of optimizations is considered not a bug, but a feature.
I would really recommend reading the Ertl paper [http://www.complang.tuwien.ac.at/kps2015/proceedings/KPS_2015_submission_29.pdf http://www.complang.tuwien.ac.at/kps2015/proceedings/KPS_201...]. It covers this really well.