gpt4 book ai didi

c - C中参数的函数转换规则是什么?

转载 作者:太空宇宙 更新时间:2023-11-04 08:06:06 24 4
gpt4 key购买 nike

我已经了解了表达式的转换规则,但我无法找到与函数参数相关的转换的位置或总结。有什么帮助吗?

最佳答案

  • 如果参数与函数原型(prototype)中声明的参数匹配,则将其转换为该类型。

  • 否则,要么没有函数原型(prototype),要么原型(prototype)以 ... 结尾且参数与省略号匹配,并且参数经历默认参数提升.

例子:

void f(char, int, ...);

signed char a = 'x';

f( 25.8 // converted (truncated) to char matching parameter
, a // converted (promoted) to int matching parameter
, a // default-promoted to int (not matching any parameter)
, 1.f) // default-promoted to double (not matching any parameter)

关于c - C中参数的函数转换规则是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42823109/

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