Edit

Share via


/Ob (Inline Function Expansion)

Controls inline expansion of functions. By default, when optimizing, expansion occurs at the compiler's discretion on all functions, often referred to as auto-inlining.

Syntax

/Ob{0|1|2|3}

/Ob{0|1|2}

Arguments

0
The default value under /Od. Disables inline expansions.

1
Allows expansion only of functions marked inline, __inline, or __forceinline, or in a C++ member function defined in a class declaration.

2
The default value under /O1 and /O2. Allows the compiler to expand any function not explicitly marked for no inlining.

3
This option specifies more aggressive inlining than /Ob2, but has the same restrictions. The /Ob3 option is available starting in Visual Studio 2019.

Remarks

The compiler treats the inline expansion options and keywords as suggestions. There's no guarantee that any function will be expanded inline. You can disable inline expansions, but you can't force the compiler to inline a particular function, even when using the __forceinline keyword.

To exclude functions from consideration as candidates for inline expansion, you can use __declspec(noinline), or a region marked by #pragma auto_inline(off) and #pragma auto_inline(on) directives. For information on another way to provide inlining hints to the compiler, see the #pragma intrinsic directive.

Note

Information that is gathered from profiling test runs overrides optimizations that would otherwise be in effect because you specified /Ob, /Os, or /Ot. For more information, see Profile-Guided Optimizations.

To set this compiler option in the Visual Studio development environment

  1. Open the project's Property Pages dialog box. For details, see Set C++ compiler and build properties in Visual Studio.

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

  3. Modify the Inline Function Expansion property.

The /Ob3 option isn't available in the Inline Function Expansion property. To set /Ob3:

  1. Open the project's Property Pages dialog box. For details, see Set C++ compiler and build properties in Visual Studio.

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

  3. Enter /Ob3 in Additional Options.

To set this compiler option programmatically

See also

/O Options (Optimize Code)
MSVC Compiler Options
MSVC Compiler Command-Line Syntax