C++ 内联 vs __inline vs __inline__ vs __forceinline?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2765164/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
inline vs __inline vs __inline__ vs __forceinline?
提问by Xavier Ho
What are the differences between these four inline (key)words?
这四个内联(关键字)词有什么区别?
inline
, __inline
, __inline__
, __forceinline
.
inline
, __inline
, __inline__
, __forceinline
.
回答by kennytm
inline
is thekeyword, in C++ and C99.
inline
是所述关键字,在C ++和C99。
__inline
is a vendor-specific keyword (e.g. MSVC) for inline function in C, since C89 doesn't have it.
__inline
是C 中内联函数的供应商特定关键字(例如MSVC),因为 C89 没有它。
__inline__
is similar to __inline
but is from another set of compilers.
__inline__
类似于__inline
但来自另一组编译器。
__forceinline
is another vendor-specific (mainly MSVC) keyword, which will apply more force to inline the function than the __inline
hint (e.g. inline even if it result in worse code).
__forceinline
是另一个特定于供应商(主要是 MSVC)的关键字,它将比__inline
提示施加更多的力量来内联函数(例如内联,即使它会导致更糟糕的代码)。
There's also __attribute__((always_inline))
in GCC and clang.
__attribute__((always_inline))
在 GCC 和 clang 中也有。
回答by CB Bailey
__inline
, __inline__
and __forceinline
are all implementation specific. Because of the double underscore they are all identifiers reserved for the implementation so shouldn't conflict with identifiers used in applications.
__inline
,__inline__
并且__forceinline
都是特定于实现的。由于双下划线,它们都是为实现保留的标识符,因此不应与应用程序中使用的标识符冲突。
inline
is the only C++ keyword.
inline
是唯一的 C++ 关键字。
回答by Holger Kretzschmar
For the Visual Studio compiler it means:
对于 Visual Studio 编译器,这意味着:
inline- suggestion to the compiler to inline your code
__forceinline- overrides the builtin compiler optimization and generates inline code
内联- 建议编译器内联您的代码
__forceinline- 覆盖内置编译器优化并生成内联代码
For more details see: http://msdn.microsoft.com/en-us/library/z8y1yy88%28VS.71%29.aspx
有关更多详细信息,请参阅:http: //msdn.microsoft.com/en-us/library/z8y1yy88%28VS.71%29.aspx