4 ms·
>The peephole optimiser will pretty certainly run first and remove the whole expression though. Which is pretty dangerous. RunCriticalCodeA(); if (x)
by Dylan16807 12y ago
>The peephole optimiser will pretty certainly run first and remove the whole expression though.
Which is pretty dangerous.
RunCriticalCodeA();
if (x) {
y = 3;
RunCriticalCodeB();
} else {
y = 4;
RunCriticalCodeB();
}
OtherCriticalCodeC();
Fail to initialize x and suddenly all that code is replaced with a return. Even the part outside the if, even the part before the if. Compilers already exist that are this aggressive.
- TheLoneWolfling 12y agoYep. Optimization by C compilers has gotten to the point of "your worst enemy is the compiler". (My favorite: I had UB in my debug function, but inside an ifdef debug block for speed purposes. So I was getting the most absurd magic errors, that only happened when I was trying to debug) As I've said, I want reads from uninitialized variables to be at least consistent. if (x) { foo(); } else { foo(); } should always run foo(). Ditto: foo(); if (x) bar(); baz(); should always run baz() (assuming everything before it is "normal" - not going to get into jumps or system exit here), should always run foo() if it runs baz(), and should always run foo().