C tail call optimization

后端 未结 8 942
陌清茗
陌清茗 2021-01-31 16:25

I often hear people say that C doesn\'t perform tail call elimination. Even though it\'s not guaranteed by the standard, isn\'t it performed in practice by any decent implement

8条回答
  •  南旧
    南旧 (楼主)
    2021-01-31 17:12

    Statements like "C doesn't perform tail call elimination" make no sense. As you correctly noted yourself, things like this depend entirely on the implementation. And yes, any decent implementation can easily turn tail-recursion into [an equivalent of] a cycle. Of course, C compilers do not normally give any guarantees about what optimizations will and what optimizations will not happen in each particular piece of code. You have to compile it and see for yourself.

提交回复
热议问题