“同级呼叫”是什么意思?意思? [英] What does "sibling calls" mean?

查看:109
本文介绍了“同级呼叫”是什么意思?意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在GCC手册上,


-foptimize-sibling-calls

-foptimize-sibling-calls


优化同级和尾部递归调用。

Optimize sibling and tail recursive calls.


我知道尾部递归调用,例如

I know tail recursive calls, for example


int sum(int n){return n == 1吗? 1:n + sum(n-1); }

int sum(int n) { return n == 1 ? 1 : n + sum(n-1); }

但是,同级调用是什么意思?

However, what does sibling calls mean?

推荐答案

尾部调用



如果函数调用是在另一个函数中执行的最后一个动作,则称为尾部调用。

Tail Calls

If a function call is a last action performed in another function, it is said to be a tail call.

该名称源于该函数调用出现在其他函数的尾部位置的事实。

The name stems from the fact that the function call appears at the tail position of other function.

int foo(int a, int b) {
    // some code ...
    return bar(b);    // Tail call which is neither sibling call nor tail recursive call.
}

bar 显示在 foo 的尾部位置。呼叫 bar 是尾部呼叫。

bar appears at the tail position of foo. Call to bar is a tail call.

尾部递归调用是尾部调用的一种特殊情况,其中被叫方功能与调用方功能相同。

Tail recursive call is a special case of tail call where callee function is same as caller function.

int foo(int a, int b) {
    if (a > 0) {
        return foo(a - 1, b + 1);    // Tail recursive call
    } else {
        return b;
    }
}






同级调用



同级调用是尾调用的另一种特殊情况,其中调用者函数和被调用者函数不必相同,但是它们具有兼容的堆栈占用空间。


Sibling Calls

Sibling call is another special case of tail call where caller function and callee function do not need to be same, but they have compatible stack footprint.

这意味着两个函数的返回类型必须相同,并且传递的参数必须使用相同的堆栈空间。

That means the return types of both functions must be same, and the arguments being passed must take same stack space.

int foo(int a, int b) {
    // some code ...
    return bar(a - 1, b);    // Sibling call, also a tail call, but not a tail recursive call.
}

每个尾部递归调用都是同级调用,因为定义暗示每个函数都是

Every tail recursive call is a sibling call, Since the definition implies every function is a sibling of itself.

因为相同的堆栈占地面积,更换堆栈框架变得相对容易。
编译器编写人员不必调整堆栈框架的大小,并且就位更改变得简单明了。

Because of identical stack footprint, replacing stack frame becomes relatively easier. Compiler writers don't have to resize stack frame, and in place mutation becomes straightforward.

这篇关于“同级呼叫”是什么意思?意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆