Which, if any, C++ compilers do tail-recursion optimization?

前端 未结 5 744
再見小時候
再見小時候 2020-11-22 12:45

It seems to me that it would work perfectly well to do tail-recursion optimization in both C and C++, yet while debugging I never seem to see a frame stack that indicates th

5条回答
  •  醉酒成梦
    2020-11-22 13:23

    As Greg mentions, compilers won't do it in debug mode. It's ok for debug builds to be slower than a prod build, but they shouldn't crash more often: and if you depend on a tail call optimization, they may do exactly that. Because of this it is often best to rewrite the tail call as an normal loop. :-(

提交回复
热议问题