c - 尾递归在C语言上真的厉害吗?

标签 c tail-recursion

我认为 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/

相关文章:

c - 在 char(8 位)上使用 Int(32 位)到 'help' 处理器

scala - 递归处理scala中的嵌套列表

haskell - 为什么这个尾递归 Haskell 函数较慢?

c - 递归函数在c中打印数字倒计时

c - ulimit -c unlimited 命令如何使用,它有什么作用?

c - 异步编程

functional-programming - 尾递归和堆栈递归函数有什么区别?

C Primer Plus 第 6 章编程练习 1

tree - 如何在序言中实现树算法的尾递归

f# - 在 F#/OCaml 中实现类似快速排序的函数的尾递归版本