标准的方式来定义在C组参数较少函数main() [英] Standard way to define parameter-less function main() in C

查看:106
本文介绍了标准的方式来定义在C组参数较少函数main()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是正确的方式,根据最新的C标准,定义功能,而无需参数: INT的main() INT主要(无效)

What is the correct way, according to the latest C standard, to define functions without parameters: int main() or int main(void)?

推荐答案

这两种形式的定义是有效的(不含的一个空隙是一个无效的原型不完整的(尽管有效)的声明)。

Both forms of definition are valid (the one without void is an invalid prototype and an incomplete (albeit valid) declaration).

形式 INT主要(无效){/ * whetever * /} 还提供了功能的原型。结果
格式为: INT的main(){/ * *无论/} 不提供一台样机(和编译器无法检查其是否正确调用)。

The form int main(void) { /* whetever */ } also provides a prototype for the function.
The form int main() { /* whatever */ } does not provide a prototype (and the compiler cannot check if it is called correctly).

请参阅标准(PDF)

6.7.5.3/14

6.7.5.3/14

这是空列表的函数声明的是,特定的功能ES科幻的科幻德说nition功能没有参数的一部分。

An empty list in a function declarator that is part of a definition of that function specifies that the function has no parameters.

之间的定义的区别: INT的main(){/ * *无论/} 结果
声明 INT主要(); 结果
原型 INT主要(无效);

difference between definition: int main() { /* whatever */ }
and declaration: int main();
and prototype: int main(void);.

定义的不提供样机;结果
声明的是有效的,但没有指定任何有关数量或类型的参数信息;结果
原型的是确定和定义兼容。

The definition does not provide a prototype;
the declaration is valid but specifies no information about the number or types of parameters;
the prototype is ok and compatible with the definition.

这篇关于标准的方式来定义在C组参数较少函数main()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆