INT main()和INT主要(无效)之间的区别? [英] Difference between int main() and int main(void)?
问题描述
什么以下意思是:
int main(void) {...}
VS
int main() {...}
我觉得 INT的main(){...}
意味着主不接受任何参数(命令行),但是:
I think that int main() {...}
means that main doesn't receive any parameters (from command line) , however:
int main(int argc, char *argv[])
确实
但什么是 INT主要(无效){...}
意味着什么?什么是的无效表示?
But what does int main(void) {...}
means ? what does the void stands for ?
我在这里看着 但它在某种程度上一个不同的问题。
I've looked here but it's somehow a different question .
推荐答案
在C ++中,没有任何区别。
In C++, there is no difference.
在C,所不同的是值得商榷的。一些爱争辩,后者版本(一个没有无效
)在技术上只是一个常见的实现扩展,并且不保证的标准,因为标准措辞的工作。但是,标准中明确规定,在函数定义空集的参数有一个良好定义的行为:该函数不带任何参数。为主要因而这样的定义在标准以下的说明相符:
In C, the difference is questionable. Some love to argue that the latter version (the one without void
) is technically just a common implementation extension and not guaranteed to work by the standard because of the wording in the standard. However, the standard clearly states that in a function definition an empty set of parameters has a well-defined behaviour: that the function does not take any parameters. Thus such a definition for main matches the following description in the standard:
据[主]应为int的返回类型和不带参数来定义。
It [main] shall be defined with a return type of int and with no parameters.
有,然而,两者之间有明显的区别:不即版本无效
未能提供正确的原型功能:
There is, however, a noticeable difference between the two: namely, the version without void
fails to provide a correct prototype for the function:
// this is OK.
int main()
{
if (0) main(42);
}
// this requires a diagnostic to be shown during compiling
int main(void)
{
if (0) main(42);
}
哦,只是为了完成:在无效
在所有函数声明的含义如下:
Oh, and just to be complete: the void
has the following meaning in all function declarators:
(6.7.6.3p10)void类型的未命名参数的特殊情况下,如在列表中的唯一项目指定函数没有参数。
(6.7.6.3p10) The special case of an unnamed parameter of type void as the only item in the list specifies that the function has no parameters.
这篇关于INT main()和INT主要(无效)之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!