/volatile (volatile Keyword Interpretation)

Specifies how the volatile keyword is to be interpreted.

Syntax

/volatile:{iso|ms}

Arguments

/volatile:iso
Selects strict volatile semantics as defined by the ISO-standard C++ language. Acquire/release semantics are not guaranteed on volatile accesses. If the compiler targets ARM (except ARM64EC), this is the default interpretation of volatile.

/volatile:ms
Selects Microsoft extended volatile semantics, which add memory ordering guarantees beyond the ISO-standard C++ language. Acquire/release semantics are guaranteed on volatile accesses. However, this option also forces the compiler to generate hardware memory barriers, which might add significant overhead on ARM and other weak memory-ordering architectures. If the compiler targets ARM64EC or any non-ARM platform, this is default interpretation of volatile.

Remarks

We strongly recommend that you use /volatile:iso along with explicit synchronization primitives and compiler intrinsics when you are dealing with memory that is shared across threads. For more information, see volatile.

If you port existing code or change this option in the middle of a project, it may be helpful to enable warning C4746 to identify code locations that are affected by the difference in semantics.

There is no #pragma equivalent to control this option.

To set the /volatile compiler option in Visual Studio

  1. Open the Property Pages dialog box for the project. For more information, see Set C++ compiler and build properties in Visual Studio.

  2. Select the Configuration Properties > C/C++ > Command Line property page.

  3. In the Additional options box, add /volatile:iso or /volatile:ms and then choose OK or Apply to save your changes.

See also

volatile
MSVC Compiler Options
MSVC Compiler Command-Line Syntax