Difference between __always_inline and inline

▼魔方 西西 提交于 2020-01-23 07:01:05

问题


There is a nice explanation of using inline instruction on another question

Could anyone explain me if there is any difference using inline and __always_inline on a header file?

And, when I would prefer __always_inline over inline or vice-versa?


回答1:


Always inline function attribute indicates that a function must be inlined. The compiler attempts to inline the function, regardless of the characteristics of the function.

However with inline attributes the compiler does not inline a function if doing so causes problems. For example, a recursive function is inlined into itself only once.

__forceinline is equivalent to __always_inline.




回答2:


This article gives some useful information: https://www.kernel.org/doc/local/inline.html

"In Linux, the keyword "__always_inline" forces a function to be inlined, and "noinline" prevents a function from being inlined. We don't use the "inline" keyword because it's broken."



来源:https://stackoverflow.com/questions/20995309/difference-between-always-inline-and-inline

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