View Single Post
  #5 (permalink)  
Old August 2nd, 2003, 08:36 PM
7stud 7stud is offline
Authorized User
Join Date: Jul 2003
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts

void main(void)
void main()

Are premissable C++ entry points.
Apparently many people do not agree with you:

What is correct: "void main()" or "int main()"?

According to the ANSI/ISO standard, the correct forms are two:

int main() { /* ... */ }
int main(int argc, char* argv[]) { /* ... */ }

Even though "void main()" will probably compile (depends on the compiler), it is not correct!

void main(void) - the Wrong Thing


void main() is not legal in C++ but is legal in C.
You've come to this page because you've said something similar to
void main() is not legal in the C language. main() is required to return int.
This is the Frequently Given Answer to that false assertion.

The ISO C++ Standard (ISO/IEC 14882:1998) specifically requires main to return int. But the ISO C Standard (ISO/IEC 9899:1999) actually does not. This comes as a surprise to many people. But despite what many documents say, including the Usenet comp.lang.c FAQ document (at great length), the actual text of the C Standard allows for main returning other types.

In my opinion, this is a defect in the C Standard that needs fixing with a corrigendum.


Reply With Quote