When doing constant propagation, the compiler analyzes variable assignments and determines if they can be changed to constant assignments. In the following example, the variable i must have a value of 7 when it is assigned to j:
i = 7;
j = i;
Instead of assigning i to j, the constant 7 can be assigned to j:
i = 7;
j = 7;
While you could make any of these changes in the source file, doing so might reduce the readability of the program. In many cases, optimizations not only increase the efficiency of the program but allow you to write more readable code without any actual efficiency loss.
Summary: Remove optimization before using a symbolic debugger.
In some cases, you might want to disable even the default optimizations. Because optimizations may rearrange code in the object file, it can become difficult to recognize parts of your code during debugging. It is usually best to remove all optimization before using a symbolic debugger. You can remove all optimization with the /Od (disable optimizations) option or the /f (fast compile) option.
You can disable all optimizations for a function by including the statement #pragma optimize( “”, off ). To restore optimization to its former state, use the statement #pragma optimize( “”, on ).