Optimizing C++ Code: Constant-Folding -- Jim Hogg
The Visual C++ Team Blog has been publishing an article series about optimizations that C++ compilers perform for you under the covers to make your code more efficient. This short nugget answers a question people sometimes ask: "What's constant folding, and why do I care?"
Optimizing C++ Code: Constant-Folding
by Jim Hogg
From the article:
This post examines Constant-Folding -- one of the simplest optimizations performed by the VC++ compiler. In this optimization, the compiler works out the result of an expression while it is compiling (at “compile-time”), and inserts the answer directly into the generated code. This avoids the cost of performing those same calculations when the program runs (at “runtime”).
Here is an example...