The C11 Standard declares that:
5.1.2.2.1 Program startup
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
intand with no parameters:int main(void) { /* ... */ }or with two parameters (referred to here as
argcandargv, 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; 10), or in some other implementation-defined manner.
10) Thus, int can be replaced by a
typedefname defined asint, or the type ofargvcan be written aschar ** argv, and so on.
We will ignore this part: or in some other implementation-defined manner. since I'm interested only in definitions equivalent to the two above examples.
Would this be a valid definition for main since char* a[4] and char** are equivalent:
int main(int argc, char* argv[4]){/*...*/}
How about a VLA array, we are assuming printf will return a positive int value:
int main(int argc, char* argv[printf("Hello there!")]){/*...*/}
argv[static 4]is also equivalent to these. - Grzegorz Szpetkowskistaticdoesn't affect the type. Of course, type qualifiers likeconstandrestrictwhich can also be used this way do affect it. - cremno