On Tue, 22 Mar 2016 11:00:24 -0500 "Marc L. Allen" <mlallen at outsitenetworks.com> wrote:
> I don't think compilers "run" your code. Provided we're talking about a C compiler, you're right. Optimizers don't run the code, they reason about it. > The fact that the code never actually allows that path to occur is > beyond the scope of most compilers, isn't it? Yes and no. If the compiler can prove a particular branch can never be taken, it can remove it because the logic of the program will not be affected. If it cannot prove that, the code will remain. For example, given int foo = 0; if (foo) exit(0); the compiler can delete lines 2 & 3. If there's no other reference to foo, it can delete line 1, too. However, extern int foo; if (foo) exit(0); and int foo = 0; extern int *pfoo; pfoo = &foo; if (foo) exit(0); both leave most optimzers flat-footed. The potential for another module to affect the value of foo means the code could run, and thus must remain. --jkl