函数返回时发生了什么

时间:2014-01-03 12:52:33

标签: c++ function

我知道当调用者函数调用被调用函数时,调用函数会推送args并返回地址,然后为被调用函数构造堆栈帧,包括push%ebp%ebx%edi%esi和push local variable。但当被叫者回来时发生了什么?

3 个答案:

答案 0 :(得分:3)

实际上C ++没有标准的应用程序二进制接口(ABI)。 C有,但程序员可能会通过应用编译器特定的调用约定来改变它。概述(机器x86)位于:http://en.wikipedia.org/wiki/X86_calling_conventions

答案 1 :(得分:0)

被调用者将返回值保存在堆栈上并返回。

答案 2 :(得分:0)

Callee函数执行以下任务

-> push the address of previous stack frame
-> push the local variables
-> performs computation
-> restores previous stack frame
-> store the function result
-> jump to return address