Possible Duplicate:
Standard way to define parameter-less function main() in 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) {}
and
int main(int argc, char* argv[]) {}
But what about empty paratheses? I know that it has another meaning than in C++ (in C, it means that number and types of parameters of this function isn't known), but I saw really much code in C with this declaration definition of main.
So who's wrong?
verb (used without object), du·pli·cat·ed, du·pli·cat·ing. to become duplicate. exactly like or corresponding to something else: duplicate copies of a letter. consisting of or existing in two identical or corresponding parts; double.
If you put a definition of a global variable in a header file, then this definition will go to every . c file that includes this header, and you will get multiple definition error because a varible may be declared multiple times but can be defined only once.
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With