gpt4 book ai didi

c - C 中的隐式声明

转载 作者:太空狗 更新时间:2023-10-29 15:25:09 25 4
gpt4 key购买 nike

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

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

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

最佳答案

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

J.2 Undefined behavior

— For call to a function without afunction prototype in scope where thefunction is defined with a functionprototype, either the prototype endswith an ellipsis or the types of thearguments after promotion are notcompatible with the types of theparameters (6.5.2.2).

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

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

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