View Single Post
Sep 2nd, 2004
0

Re: Why NOT void main()

Not declaring a function's return value is an error in C++, whether the function is main or not. In C99, the October 1999 revision to Standard C, not declaring a function's return value is also an error (in the previous version of Standard C an implicit int was assumed as the return value if a function was declared/defined without a return value). But the usual requirement of both Standard C++ and Standard C is that main should be declared to return an int. In other words, this is an acceptable form of main:
C++ Syntax (Toggle Plain Text)
  1. int main(void) { /* ... */ }

The problem is that this code declares main to return a void and that's just no good for a strictly conforming program. Neither is this:

implicit int not allowed in C++ or C99
C++ Syntax (Toggle Plain Text)
  1. main() { /* ...Whatever... */ }


Hope this helps,
- Stack Overflow
Reputation Points: 26
Solved Threads: 4
Junior Poster
Stack Overflow is offline Offline
185 posts
since Sep 2004