4 ms·
I think you are right there is no reliable way, but C specification does not disallow unreliable programs. It only disallows nonconforming programs. Compilers
by sanxiyn 6y ago
I think you are right there is no reliable way, but C specification does not disallow unreliable programs. It only disallows nonconforming programs.
Compilers can't optimize a() to b() under pointers-are-integers model. It may be linked to code like c():
void c() {
int random = generate_random_number();
int* address = (int*)random;
*address = 4;
}
In real machines, c() randomly overwrites memory with 4, in particular memory of x whose value will change from 5 to 4. In C abstract machine, c() randomly overwrites memory with 4, but it can never overwrite memory of x, because memory of x does not have integer address. Therefore compilers can optimize a() to b().