2

例如

int foo(short x);
short s = -1; 
foo(s);

是否与

//int foo(short x); //Updated
int foo(signed x);
short s = -1; 
foo((signed)s);//sign-extend and push to stack

或者它是否与

//int foo(short x); //Updated
int foo(unsigned)
short s = -1; 
foo((unsigned)(unsigned short)s);//zero-extend and push to stack

或者两者都可以(我们将高位视为脏)?

我可以在特殊编译器上做一些实验。但我不确定每一件事都非常详细。我只需要一些正式的承诺。

4

1 回答 1

2

cdecl 似乎是应用程序二进制接口的不完整规范。我希望它依赖于 System V 应用程序二进制接口的完整性。我找不到对此的明确陈述。

来自System V Application Binary Interface: Intel386 Architecture Processor Supplement的第 43 页,“函数将所有整数值参数作为字传递,根据需要扩展或填充有符号或无符号字节和半字。”</p>

这是模糊的,因为它没有指定参数是否应该通过符号扩展、零填充或其他方式进行扩展。我会将其解释为添加位的内容是未指定的,因此调用者可以传递任何值,而被调用者不应使用额外的位。

请注意,C 函数调用中的强制转换表达式不会对参数的传递方式产生任何影响。传递参数的类型由函数声明决定。我将您提供的示例代码解释为传递不同大小整数的概念的伪代码,而不是实际的 C 代码。

于 2013-12-09T18:32:05.780 回答