gpt4 book ai didi

gcc - 在 CDECL 调用约定中,我可以重用我压入堆栈的参数吗?

转载 作者:行者123 更新时间:2023-12-04 19:00:20 26 4
gpt4 key购买 nike

在海湾合作委员会 cdecl调用约定,在调用返回后,我是否可以依赖我压入堆栈的参数相同?即使混合 ASM 和 C 并启用优化( -O2 )?

最佳答案

一句话:没有。

考虑这个代码:

__cdecl int foo(int a, int b)
{
a = 5;
b = 6;
return a + b;
}

int main()
{
return foo(1, 2);
}

这产生了这个 asm 输出(用 -O0 编译):
movl    $5, 8(%ebp)
movl $6, 12(%ebp)
movl 8(%ebp), %edx
movl 12(%ebp), %eax
addl %edx, %eax
popl %ebp
ret

因此,__cdecl 函数很可能会踩踏堆栈值。

这甚至不包括内联或其他优化魔法的可能性,其中事情可能不会首先出现在堆栈中。

关于gcc - 在 CDECL 调用约定中,我可以重用我压入堆栈的参数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38844016/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com