The compiler can perform extremely aggressive optimizations. These optimizations produce high code quality both in terms of speed and size. Certain programs, however, cannot be optimized with the technologies enabled by the /Oz option. For these programs, you should not specify this option; you can still use all other optimization options.
Because the optimization strategies enabled by the /Oz option are so aggressive, they are not part of the maximum optimization (/Ox) option.
Examples of the effects of the /Oz option are
Loop optimization (/Ol). Loop optimization enables a technology that anticipates program flow and tries to remove invariant expressions from loops. When you specify the enable aggressive optimizations option (/Oz), the compiler removes invariant expressions even when it might cause an error. Errors with the enable aggressive optimizations option occur most often when an invariant expression that can cause an exception is protected by an if statement. The invariant expression is hoisted out of the loop body, causing it to be evaluated prior to the evaluation of the if statement that was designed to protect it. Here are two examples that illustrate this problem:
for( i = 0; i 100; ++i )
if( float_val != 0.0F )
/* Protect against divide-by-zero. */
float_result = pi / float_val;
while( condition )
if( ptr_val != NULL )
/* Protect pointer dereference. */
char_var = *ptr_val;
Global register allocation (/Oe). The enable aggressive optimizations option enables some register allocation strategies that can cause invalid segment selectors to be placed in registers. Although this problem is benign in DOS, it causes protection faults in Windows.
Note:
You can instruct the compiler to enable aggressive optimizations on a function-by-function basis by using the optimize pragma with the z option.