我认为 Tail-recursive对函数式编程语言很有帮助。 C呢?
- C 语言或编译器是否支持尾调用消除?
- 程序是否为新调用创建了新的栈帧?
来自维基:
Tail calls can be implemented without adding a new stack frame to the call stack. Most of the frame of the current procedure is not needed any more, and it can be replaced by the frame of the tail call, modified as appropriate (similar to overlay for processes, but for function calls).
The program can then jump to the called subroutine. Producing such code instead of a standard call sequence is called tail call elimination.
最佳答案
尾递归通常用在函数式语言中,因为它是在结构上实现循环的自然方式,而在过程语言中实际上并没有那么多递归。
因此过程语言不需要它。但是,由编译器决定是否找到此类优化。
关于c - 尾递归在C语言上真的厉害吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35157410/