Hacker News new | ask | show | jobs
by lhecker 3871 days ago
AFAIK most compiler will do tail-recursion optimization if the method ends in a tail call to the current function (obviously) or to a "sibling" function (i.e. if a() calls b() which calls a() again and so on) and is sufficiently short to be suitable for inlining.

It's important to remember local objects with destructors will make this impossible, since destructors are run at the end of the function scope and thus after what's seemingly a perfect tail call.

2 comments

I almost regretted asking since google answered my question in seconds, but the destructor thing would never have occured to me.
+1 about the point on destructors. Easy to overlook.