c - C99 标准中的默认参数提升

标签 c function prototype c99 promotions

我对 C99 标准中的默认参数提升有疑问。在“C Programming - A Modern Approach, 2nd Edition”一书中,我读到:

Argument Conversions:

[...]

1) The compiler has encountered a prototype prior to the call. [...]

2) The compiler has not encountered a prototype prior to the call. The compiler performs the default argument promotions: (1)floatarguments are converted todouble. (2) The integral promotions are performed, causingcharandshortarguments to be converted toint. (In C99, the integer promotions are performed.)

几行进一步显示了一个示例,其中在调用它之前没有函数原型(prototype)或定义。评论如下:

Of course, a much better solution is to provide a prototype forsquarebefore calling it. In C99, callingsquarewithout first providing a declaration or definition of the function is an error.

这两个草句不是互相矛盾吗?我的意思是,如果 C99 禁止在没有事先声明/定义的情况下调用函数,它如何确定那种函数调用中的提升?

最佳答案

不,它们并不矛盾。

声明不一定是原型(prototype):

int f();

声明函数 f 但不是原型(prototype),因为对参数类型一无所知。

int (a)
 in a;
{
 ...
}

是定义,但也不是原型(prototype)。

关于c - C99 标准中的默认参数提升,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12008951/

相关文章:

php - PHP 函数可以接受无限数量的参数吗?

javascript - 获取自定义对象构造函数名称

javascript - 一个(有点晦涩的)Javascript 继承问题

javascript - 如何在 Javascript 中使用面向方面编程 "catch"关注?

Javascript - 私有(private)变量起作用?

c - malloced数组VS。变长数组

c - 如何创建我自己的库以开始使用操作系统?

c - C 中的图像处理——处理一个 256 色位图图像

C:帮助理解指针

c++ - 将具有可变边界的二维数组传递给函数