When does the compiler listen to the inline specifier

This is a discussion on When does the compiler listen to the inline specifier within the C++ Programming forums, part of the General Programming Boards category; This simple program does not expand the inline functions. After the code there is a listing of masm and source ...

When does the compiler listen to the inline specifier

This simple program does not expand the inline functions. After the code there is a listing of masm and source code showing its not inlining. Rather it calling the function doin' the whole epilog then function then prolog rather than expanding the code in place. I've tried without the inline specifier which defaults to inline when defined in the class (which it is).

if you are using visual c (and i guess you are) then check out __forceinline.

inline, __inline, __forceinline
inline

function_declarator; // C++ Specific

__inline

function_declarator;// Microsoft Specific

__forceinline

function_declarator;// Microsoft Specific

The inline and __inline keywords allow the compiler to insert a copy of the function body into each place the function is called. The insertion occurs only if the compiler's cost/benefit analysis show it to be profitable. The __forceinline keyword overrides the cost/benefit analysis and relies on the judgement of the programmer instead. Exercise caution when using __forceinline. Indiscriminate use of __forceinline can result in larger code with only marginal performance gains or, in some cases, even performance losses (due to increased paging of a larger executable, for example).

You cannot force the compiler to inline a function when conditions other than cost/benefit analysis prevent it. You cannot inline a function if:

The function or its caller is compiled with /Ob0 (the default option for debug builds).

The function and the caller use different types of exception handling (C++ exception handling in one, structured exception handling in the other).

The function has a variable argument list.

The function uses inline assembly and is not compiled with /Og, /Ox, /O1, or /O2).

Function returns an unwindable object by value and is not compiled with /GX, /EHs, or /EHa).

The function receives a copy-constructed object passed by value, when compiled with /GX, /EHs,, or /EHa.

The function is recursive and is not accompanied by #pragma(inline_recursion, on). With the pragma, recursive functions can be inlined to a default depth of eight calls. To change the inlining depth, use #pragma(inline_depth, n).
If the compiler cannot inline a function declared __forceinline, it generates a level 1 warning (4714).

The inline keyword is available only in C++. The __inline and __forceinline keywords are available in both C and C++. For compatibility with previous versions, _inline is a synonym for __inline.

Using inline functions can make your program faster because they eliminate the overhead associated with function calls. Functions expanded inline are subject to code optimizations not available to normal functions.

inline int max( int a , int b )
{
if( a > b ) return a;
return b;
}
A class's member functions can be declared inline either by using the inline keyword or by placing the function definition within the class definition.

When does the compiler listen to the inline specifier

Are you compiling the debug build? The compiler can't inline functions if the /ZI compiler option is enabled. I compiled your code in release build and by changing the debug option to /Zi (and enabled inling in optimisations) and in both cases even without the inline specifiers in the source code the functions were inlined in the asm output.