问题
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