What is tail call optimization?

前端 未结 10 1247
一整个雨季
一整个雨季 2020-11-21 06:36

Very simply, what is tail-call optimization?

More specifically, what are some small code snippets where it could be applied, and where not, with an explanation of wh

10条回答
  •  感动是毒
    2020-11-21 07:16

    1. We should ensure that there are no goto statements in the function itself .. taken care by function call being the last thing in the callee function.

    2. Large scale recursions can use this for optimizations, but in small scale, the instruction overhead for making the function call a tail call reduces the actual purpose.

    3. TCO might cause a forever running function:

      void eternity()
      {
          eternity();
      }
      

提交回复
热议问题