duong_dajgja
duong_dajgja

Reputation: 4276

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

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"?

Upvotes: 0

Views: 133

Answers (1)

DannyNiu
DannyNiu

Reputation: 1513

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.

Upvotes: 0

Related Questions