Declare main prototype

user318904 picture user318904 · Feb 16, 2011 · Viewed 18.3k times · Source

Is there any reason why I never see main's prototype declared in C programs, ie:

int main(int argc, char* argv[]);

int main(int argc, char* argv[])
{
    return 0;
}

Always seemed inconsistent..

Answer

John Bode picture John Bode · Feb 16, 2011

C language standard, draft n1256:

5.1.2.2.1 Program startup

1 The function called at program startup is named main. The implementation declares no prototype for this function. It shall be defined with a return type of int and with no parameters:

int main(void) { /* ... */ }

or with two parameters (referred to here as argc and argv, though any names may be used, as they are local to the function in which they are declared):

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

or equivalent;9) or in some other implementation-defined manner.

Emphasis mine.