/Oa, /Ow   (Assume No Aliasing, Assume Aliasing Across Function Calls)

HomeOverviewHow Do ICompiler Options

Feature Only in Professional and Enterprise Editions   Code optimization is supported only in Visual C++ Professional and Enterprise Editions. For more information, see Visual C++ Editions.

Aliasing can slow your application by reducing both register storage of variables and loop optimizations.

The Assume No Aliasing (/Oa) option tells the compiler that your program does not use aliasing. An alias is a name that refers to a memory location that is already referred to by a different name.

The Assume Aliasing Across Function Calls (/Ow) option tells the compiler that no aliasing occurs within function bodies but might occur across function calls. After each function call, pointer variables must be reloaded from memory.

To find these options in the development environment, click Settings on the Project menu. Then click the C/C++ tab, and click Optimizations in the Category box. Under Optimizations, click Customize.

Rules for using /Oa and /Ow

The following rules must be followed for any variable not declared as volatile, or else /Oa and /Ow are ignored. In these rules, a variable is referenced if it is on either side of an assignment or if a function uses it in an argument:

Aliasing bugs most frequently show up as corrupted data. If variables are assigned seemingly random values, compile the program with Disable (/Od). If the program works when compiled with the /Od option, do not use /Oa or /Ow.

The following code fragment could have an aliasing problem:

i = -100;
while( i < 0 )
{
    i += x + y;
    *p = i;
}

Without /Oa or /Ow, the compiler must assume that x or y could be modified by the assignment to *p and cannot assume that x + y is constant for each loop iteration. If you specify /Oa or /Ow, the compiler assumes that modifying *p cannot affect either x or y and x + y can be removed from the loop.

Note   You can disable optimizations around code that uses aliasing (for individual functions) by using #pragma optimize with the a or w option.