For those who actually like to mess with the low-level stuff, here is an assembly language template for an optimized tail-call.
这里是为那些真正热衷底层编程的人准备的一个优化尾部调用的汇编语言模板。
The only problem is that right now very few compilers implement tail-call optimizations.
惟一的问题在于,现在只有非常少的编译器实现了尾部调用优化。
The idea of removing stack frames after tail-calls is called tail-call optimization.
在尾部调用之后除去栈结构的方法称为尾部调用优化。
As you can see in order for the call to be a true tail-call, no other operation can be performed on the result of the tail-called function before it is passed back.
可见,要使调用成为真正的尾部调用,在尾部调用函数返回之前,对其结果不能执行任何其他操作。
For example, the print_report_i function described earlier compiled with tail-call optimization using -O2 on GCC 3.4 and therefore runs with a stack-size that is constant, not growing linearly.
例如,前面描述的 print_report_i函数在GCC 3.4 中使用-O2 进行尾部调用优化编译,因此运行时使用的栈的大小是固定的,而不是线性增长的。
For example, the print_report_i function described earlier compiled with tail-call optimization using -O2 on GCC 3.4 and therefore runs with a stack-size that is constant, not growing linearly.
例如,前面描述的 print_report_i函数在GCC 3.4 中使用-O2 进行尾部调用优化编译,因此运行时使用的栈的大小是固定的,而不是线性增长的。
应用推荐