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

OverviewHow 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 .

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:

  • No pointer references a variable that is used directly.

  • No variable is used directly if a pointer to the variable is being used.

  • No variable is used directly if the variable’s address is taken within a function.

  • No pointer is used to access a memory location if another pointer is used to modify the same memory location.

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*pand cannot assume thatx + yis constant for each loop iteration. If you specify /Oa or /Ow, the compiler assumes that modifying*pcannot affect eitherxoryandx + ycan 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.