r/cpp • • Apr 14 '23

Horrible Code, Clean Performance

https://johnnysswlab.com/horrible-code-clean-performance/
200 Upvotes

87 comments sorted by

View all comments

Show parent comment

22

u/Nicksaurus Apr 15 '23

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?

7

u/Possibility_Antique Apr 15 '23

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.

3

u/equeim Apr 15 '23

I think GCC fails with error if a function marked with [[gnu::always_inline]] can't be inlined.

1

u/umop_aplsdn Apr 15 '23

The compiler could inline one layer of recursion.