From ISO/IEC 9899:2024, 5.1.2.3.2, 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 ofint
and with no parameters:int main(void) { /* ... */ }
or with two parameters (referred to here as
argc
andargv
, 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;6) or in some other implementation-defined manner.
And a footnote at the end of the page says:
- Thus,
int
can be replaced by a typedef name defined asint
, or the type ofargv
can be written aschar ** argv
, or the
return type may be specified bytypeof(1)
, and so on.
From this, I conclude that the prototype for main()
can be any of the following:
1. int main(void) { /* ... */ }
/* Because function declarations whose parameter list is empty is treated the same
as a parameter list that contains only a single void in C23. */
2. int main() { /* ... */ }
3. int main(int argc, char *argv[]) { /* ... */ }
4. int main(int argc, char **argv) { /* ... */ }
/* Or any other value than 1 that fits in the range of an int. */
5. typeof(1) main() { /* ... */ } /* And all the other aforementioned variants as well. */
6. typedef int val;
val main(val argc, char **argv) { /* ... */ } /* And all the other aforementioned variants as well. */
Are there any other types that are equivalent? @Davislor from https://codereview.stackexchange.com says that:
And 6.7.6.3 says that, in a function declaration,
*argv[]
andconst **argv
are “compatible types.”
So the 7th variant can be:
7. int main(int argc, char const **argv) { /* ... */ }
Well then what about:
int main(const int argc, char const **argv) { /* ... */ }
And other compatible types, if any is left?