C does not support function overloading. How can we then have 3 prototypes for main? What is the historical reason for having 3 prototypes?
            Asked
            
        
        
            Active
            
        
            Viewed 162 times
        
    1 Answers
9
            There are only two prototypes for main that a standard-conforming C implementation is required to recognize: int main(void) and int main(int, char *[]). This is not overloading, since there can still only be one main per program; having a void foo(int, double) in one program and a char *foo(FILE *) in another isn't overloading either.
The reason for the two prototypes is convenience: some applications want command-line arguments, while others don't bother with them.
All other prototypes, such as void main(void) and int main(int, char *[], char *[]), are compiler/platform-dependent extensions.
 
    
    
        Fred Foo
        
- 355,277
- 75
- 744
- 836
- 
                    There are only two _canonical_ forms of `main` and the second also has the text "or equivalent" tacked on (so `char**` is okay). In addition, the standard also _explicitly_ allows others - it just doesn't mandate them. – paxdiablo Sep 27 '11 at 12:37
- 
                    @paxdiablo: I decided not to bother with equivalent forms since they're already handled by other rules in the standard. Thanks for the other remark, added "required" to the answer. – Fred Foo Sep 27 '11 at 12:39
- 
                    This only answers how it works on a hosted system. For a complete answer check this link: http://stackoverflow.com/questions/5296163/why-is-the-type-of-the-main-function-in-c-and-c-left-to-the-user-to-define/5296593#5296593 – Lundin Sep 27 '11 at 14:24
