I'm using Visual Studio 2005 and I was writing a while loop like this (C++):
const bool x = GetSomeBool();
while (running) {
if (x) FuncA();
FuncB();
}
Since 'x' is const and it can know the result of the if every time, will the compiler perform the following optimisation?:
if (x) while(running) { FuncA(); FuncB(); }
else while(running) { FuncB(); }
Is it smart enough to do that? The performance of this while is important, and I actually have 4 or 5 ifs. Writing out every combination is lengthy in the source code, but would the compiler do this for me?