Export (0) Print
Expand All

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

Visual Studio .NET 2003
/Oa
/Ow

Aliasing (the use of multiple names that refer to the same memory location) can prevent some optimizations, such as register storage of variables and loop optimizations.

/Oa tells the compiler that your program does not use aliasing.

/Ow tells the compiler that your program does not use aliasing within functions but may use aliasing across function calls. As a result, pointer variables must be reloaded from memory after each function call.

Rules for Using /Oa and /Ow

If you use /Oa or /Ow, you must follow these rules. The following rules apply for any variable not declared as volatile:

  • No pointer can reference a variable that is used directly (a variable is referenced if it is on either side of an assignment or if a function uses it in an argument).
  • No variable can be used directly if a pointer to the variable is being used.
  • No variable can be used directly if its address is taken within a function.
  • No pointer can be used to access a memory location if another pointer modifies the same memory location.

Failing to follow these rules can cause corrupted data. If variables seem to take on random values, compile the program with Disable (/Od). If the problem goes away, try compiling with optimization but without /Oa or /Ow.

The following code can cause an aliasing problem:

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

Without /Oa or /Ow, the compiler assumes that the assignment to *p can modify x or y, so it does not assume that x + y is constant for each iteration. If you specify /Oa or /Ow, the compiler assumes that modifying *p does not affect x or y and the calculation of 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.

To set this compiler option in the Visual Studio development environment

  1. Open the project's Property Pages dialog box. For details, see Setting Visual C++ Project Properties.
  2. Click the C/C++ folder.
  3. Click the Command Line property page.
  4. Type the compiler option in the Additional Options box.

To set this compiler option programmatically

See AdditionalOptions.

See Also

/O Options (Optimize Code) | Compiler Options | Setting Compiler Options

Show:
© 2014 Microsoft