In C, the implementation is allowed to support basically any type for the main
function, so it may very well be that your particular implementation allows the various forms you have proposed. (And indeed it seems to allow the three-parameter version that exposes the environment.) However, the implementation is only required to accept the two forms
int main(void)
and
int main(int, char**)
Since int(int, const char**)
isn't the same type as int(int, char**)
, your proposed "constified" version is not strictly speaking required to be supported and falls under the first rule. It is, however, quite likely to work since char*
and const char*
are laid out the same way as far as the ABI is concerned, and the data you're given is mutable anyway.
Note further that int f(int)
and int f(const int)
are the same identical prototype, so there is no problem here regarding top-level qualifications of the parameters.
main
. Also, the const in "const char*" isn't top-level and matters very much. - Kerrek SB