星期一, 9月 28, 2009

Microsoft Specfic _inline, __inline, __forceinline.

http://msdn.microsoft.com/zh-tw/library/z8y1yy88.aspx

  • _inline = __inline = inline.
  • inline 是 C++ Standard, _inline, __inline, __forceinline 是 Microsoft Specfic.
  • Microsoft 的 _inline, __inline, __forceinline 可使用在 C 裡面.
  • inline function 是否真正會有作用, 是與 compiler 處理有關, 通常要加上最佳化函數才有效.
  • 遞迴不會 inline, 除非加上 #pragma inline_recursion(on), 限制為 16 層.
  • 其實 inline 不一定會增加效率. (重要)
Microsoft Specific

The __inline keyword is equivalent to inline.

Even with __forceinline, the compiler cannot inline code in all circumstances. The compiler 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, unless compiled with /Og, /Ox, /O1, or /O2.

The function is recursive and not accompanied by #pragma inline_recursion(on). With the pragma, recursive functions are inlined to a default depth of 16 calls. To reduce the inlining depth, use inline_depth pragma.

The function is virtual and is called virtually. Direct calls to virtual functions can be inlined.

The program takes the address of the function and the call is made via the pointer to the function. Direct calls to functions that have had their address taken can be inlined.

The function is also marked with the naked __declspec modifier.

If the compiler cannot inline a function declared with __forceinline, it generates a level 1 warning.

Recursive functions can be substituted inline to a depth specified by the inline_depth pragma, up to a maximum of 16 calls. After that depth, recursive function calls are treated as calls to an instance of the function. The depth to which recursive functions are examined by the inline heuristic cannot exceed 16. The inline_recursion pragma controls the inline expansion of a function currently under expansion. See the Inline-Function Expansion (/Ob) compiler option for related information.
END Microsoft Specific



沒有留言: