Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在cdecl调用约定中,有符号字符和短字符如何作为参数传递_C_Calling Convention_Cdecl - Fatal编程技术网

在cdecl调用约定中,有符号字符和短字符如何作为参数传递

在cdecl调用约定中,有符号字符和短字符如何作为参数传递,c,calling-convention,cdecl,C,Calling Convention,Cdecl,比如说 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)(unsigne

比如说

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
还是和你一样

//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
或者两者都可以(我们将高位视为脏位)


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

cdecl似乎是应用程序二进制接口的不完整规范。我希望它的完整性依赖于SystemV应用程序二进制接口。我找不到关于这一点的明确说明

从第43页开始,“函数将所有整数值参数作为字传递,根据需要展开或填充有符号或无符号字节和半字。”

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


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

编译器实现细节有什么区别?你不能用这些高位做任何事,如果你是用其他语言编写的,需要与C例程互操作,或者如果你写的C实现需要与其他C实现互操作。你是说当函数原型时,你认为一个比短< /Cord>大的数字被推到堆栈中。是
intfoo(短x)
?为什么会这样?@Floris:应用程序二进制接口会为推送到堆栈的参数指定最小大小,以便堆栈保持所需的对齐方式。@Floris:问题是关于特定的C实现,而不是关于C标准。C标签并不意味着问题是关于C标准的。“C”不仅仅是指标准C;除了标准之外,还有其他版本的C。此外,有些人添加标记是因为问题涉及标记的主题,而不是因为它直接涉及标记的主题。标题明确指出问题是关于cdecl调用约定的。是的,我想我已经得到了我想要的。在我的示例中确实存在一些问题。参数在通过之前可能会再次转换为short。我会更新它。谢谢。