作者Lapha (lapha)
看板CSSE
标题Re: [问题] 请问calling convention..
时间Sun Jun 24 17:13:13 2007
※ 引述《l314 (红虫)》之铭言:
: 请问一下calling convention,
: caller save register及callee save register,与下面这些叙述有什麽关联吗?
: pascal convention 规定:三数传递次序由左而右,stack frame 的清理由被呼叫端(
: callee)负责。
: c convention 规定:三数传递次序由右而左,stack frame 的清理由呼叫端(caller)
: 负责。
: 由於 pascal convention 规定 stack frame 的清理由被呼叫端(callee)负责,因此如
: 对同一函式呼叫一千次,其 stack frame cleanup routine只需一份(位於 callee 内,
: 由编译器加入)。
: 由於 c convention 规定 stack frame 的清理由呼叫端(caller)负责,因此对同一个
: 函式呼叫一千次,其 stack frame cleanup routine需 1000 份(位於呼叫点,由编译器
: 加入)。
: 因此,采用 pascal calling convention,对於降低程式码大小(并因而增加执行速度)
: ,在某些情况下很有帮助。这是为什麽早期 Windows 系统内部几乎完全采用 pascal
: calling convention 的原因。
: 但是 pascall convention 不支援「个数不定之引数」。例如 printf()的引数个数不一
: 定,那就一定得使用 c calling convention。
对不确定参数个数的函式来说, caller才知道该如何呼叫pop()来清除stack, callee就不晓得了,
所以这种情况下, c convention 才能支援
http://www.unixwiz.net/techtips/win32-callconv.html 有比较完整的解说
: 还有下面这句,我也不太懂它的意思..
: If a procedure is called n times, then the portion of the calling sequence in
: the various callers is generated n times. However, the portion of the callee
: is shared by calls, so it is generated just once. Hence, it is desirable to
: put as much of the calling sequence into the callee as possible.
: 最後请问calling convention与call by value, call by reference, call by name..
calling convention 应该是指 caller 和 callee 函式间, 参数或回传值在传递过程中在
记忆空间中的存放顺序、结束时由谁负责清除之类的规则..
和call by value等所指的应该是不一样的东西
: 又有什麽关联呢?
: 请问小弟我是不是什麽核心观念没弄清楚,所以才会产生前述的混淆..
: 请板上前辈指点一下..谢谢..
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 203.73.164.188
※ 编辑: Lapha 来自: 203.73.164.188 (06/24 17:15)
1F:推 l314:谢谢您~~ ^^ 06/25 12:13