inline vs __inline vs __inline__ vs __forceinline?

流过昼夜 提交于 2019-12-02 15:02:45
kennytm

inline is the keyword, in C++ and C99.

__inline is a vendor-specific keyword (e.g. MSVC) for inline function in C, since C89 doesn't have it.

__inline__ is similar to __inline but is from another set of compilers.

__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).

There's also __attribute__((always_inline)) in GCC and clang.

__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 is the only C++ keyword.

For the Visual Studio compiler it means:

  • inline - suggestion to the compiler to inline your code

  • __forceinline - overrides the builtin compiler optimization and generates inline code

For more details see: http://msdn.microsoft.com/en-us/library/z8y1yy88%28VS.71%29.aspx

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!