c - C 中的隐式声明

标签 c c99 undefined-behavior language-lawyer implicit-declaration

下面的程序是否调用了 C 中的 Undefined Behaviour

int main()
{
    printf("Printf asking: Where is my declaration ?");
}

在上面的程序中有一个printf()的隐式声明,那么上面的代码是完全符合标准还是只是有一些特定于实现的行为?

最佳答案

是的。在范围内没有声明是 UB。

J.2 Undefined behavior

— For call to a function without a function prototype in scope where the function is defined with a function prototype, either the prototype ends with an ellipsis or the types of the arguments after promotion are not compatible with the types of the parameters (6.5.2.2).

另外,请注意,在 C99 中,从 main 中退出是可以的(即在语义上等同于 return 0;)。对于 C99 之前的兼容编译器,您需要一个 return 语句,其中 main 函数的返回类型是与 int 兼容的类型。

关于c - C 中的隐式声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3528164/

相关文章:

c - 为什么即使我没有尝试修改字符串,C 中的字符串也会被修改?

c - 为给定输入生成以下位掩码的最佳方法?

c - 设置值等于自身

c - 下标具有寄存器存储类的数组

c - 如何按字母顺序在列表中插入结构体

c - 如何使用循环制作多个文件?

c - C99中 "arithmetic operation"的定义是什么?

javascript - undefined variable 何时抛出 Uncaught TypeError 而不是仅仅具有值 'undefined' ?

c++ - 为什么 “i++ + 1”本身未定义?如何确保后缀的副作用在计算+之后发生?

c - 为什么这些构造使用增量前和增量后未定义的行为?