Is tail call (including tail recursion) compiler/implementation dependent?

79 Views Asked by At

Searching tail recursion on the internet I stumbled on How does compiler know whether the recursion is a tail recursion or not and how does it optimize tail recursion. If I understand correctly then the reason for tail recursion being faster than non-tail recursion is that compliers don't create stack frames for new function calls. Then it is compiler dependent right? Is it always guaranteed on all compilers for all languages? Also, if it is compiler dependent then why do many people keep calling it "algorithm"?

1

There are 1 best solutions below

0
DannyNiu On

Yes, tail-call (recursive or not) optimization is implementation-dependent. And no, if compiler isn't smart enough yet, it won't be able to detect at least some of the tail calls.