c)中的主要定义( [英] Definition of main() in C
问题描述
可能重复:结果
<一href=\"http://stackoverflow.com/questions/8022274/standard-way-to-define-parameter-less-function-main-in-c\">Standard的方式来定义无参数的函数main()用C
我可以使用声明的函数定义的main()
在C,它是这样的:
Can I use a declaration definition of function main()
in C that looks like:
int main() {}
是的,我看到的标准说,只有两种担保支持的版本:
Yes, I saw that standard says that there are only two guaranteed-supported versions:
int main(void) {}
和
int main(int argc, char* argv[]) {}
但对于空paratheses?我知道它有另外的含义比C ++(C语言,它意味着不知道这个函数的参数数量和类型),但我看到真多code用C本声明的主要定义。
那么,谁是错的?
推荐答案
在C,还有的的的声明之间的差异的 INT主要();
和 INT主要(无效);
(前宣布用的未指定的若干参数的函数,而后者实际上是调用一个原与害羞;键入的)。然而,在功能的定义的,无论是的main()
和主要(无效)
定义一个函数,它的没有的参数。
In C, there's a difference between the declarations int main();
and int main(void);
(the former declares a function with an unspecified number of arguments, and the latter is actually called a prototype). However, in the function definition, both main()
and main(void)
define a function that takes no arguments.
其他的签名,主(INT,CHAR **)
,是一个替代的形式。顺应的实现必须接受两种形式,但也可以接受其他实现定义签名的main()
。任何给定的程序可能当然只包含的有一个的称为单一功能的主
。
The other signature, main(int, char**)
, is an alternative form. Conforming implementations must accept either form, but may also accept other implementation-defined signatures for main()
. Any given program may of course only contain one single function called main
.
这篇关于c)中的主要定义(的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!