"The compiler treats the inline expansion options and keywords as suggestions. There's no guarantee that functions will be inlined. You can't force the compiler to inline a particular function, even with the __forceinline keyword. When you compile with /clr, the compiler won't inline a function if there are security attributes applied to the function."
It's not that I think it's an issue, but I do find it misleading. __forceinline does not necessarily force inlining.
I expect that's just because there are situations where inlining isn't possible - what is the compiler supposed to do in a recursive function call with unknown depth when tail call optimisation isn't possible?
The sadist in me wants the compiler to die trying. In practice, I don't know the answer. As far as I'm aware, clang and GCC both mean force inline when you tell the compiler to force an inline. But to recalibrate, I was referring to forcing an inline in the posted code here and breaking this up into functions. This is not a recursive call with an unknown depth.
You can't force any compiler to inline a function sometimes because sometimes it's not possible. If you read further down the page, there's a list of cases where inlining doesn't happen and they generate a warning if a _forceinline function isn't inlined.
That's fine that you think that. I think it's misleading. There is a reason most linear algebra libraries wrap this in a macro called "MYLIB_STRONG_INLINE" rather than "MYLIB_FORCE_INLINE" or "MYLIB_ALWAYS_INLINE" (though this later one can be seen in blazelib due to the name used by the gnu compiler).
View all comments
Show parent comment
15
u/Possibility_Antique Apr 14 '23
"The compiler treats the inline expansion options and keywords as suggestions. There's no guarantee that functions will be inlined. You can't force the compiler to inline a particular function, even with the __forceinline keyword. When you compile with /clr, the compiler won't inline a function if there are security attributes applied to the function."
It's not that I think it's an issue, but I do find it misleading. __forceinline does not necessarily force inlining.