E
ec429
Niggly standards question, it's just been bugging me:
Of course we all know that main's declaration should be either
int main(void)
or
int main(int argc, char *argv[])
BUT... is it legal to use
int main(int argc, const char *argv[])
instead? The FAQ (11.12a) doesn't mention qualifiers at all, only 'char
** argv', the irrelevance of the names, and old-style syntax. Having
inspected the C99 standard (N1124), I see (from 5.1.2.2.1p1) that the
parameters need only be "equivalent", with a footnote that "int can be
replaced by a typedef name defined as int, or the type of argv can be
written as char ** argv, and so on."
However, I cannot find a definition in the standard of 'equivalent'
types, only of compatible types (6.2.7). Of course it is legal to call
a function taking a 'const char *' and pass it a 'char *', because
const-ness can always be added.
Logically, then, it /ought/ to be legal, but the standard isn't clear
enough for me to be sure. Also, if it is legal, it seems like a good
thing to do in most cases (as a program is unlikely to need to modify
its argv) if one is trying to make full use of _const_.
So, is it legal or not?
-Edward
Of course we all know that main's declaration should be either
int main(void)
or
int main(int argc, char *argv[])
BUT... is it legal to use
int main(int argc, const char *argv[])
instead? The FAQ (11.12a) doesn't mention qualifiers at all, only 'char
** argv', the irrelevance of the names, and old-style syntax. Having
inspected the C99 standard (N1124), I see (from 5.1.2.2.1p1) that the
parameters need only be "equivalent", with a footnote that "int can be
replaced by a typedef name defined as int, or the type of argv can be
written as char ** argv, and so on."
However, I cannot find a definition in the standard of 'equivalent'
types, only of compatible types (6.2.7). Of course it is legal to call
a function taking a 'const char *' and pass it a 'char *', because
const-ness can always be added.
Logically, then, it /ought/ to be legal, but the standard isn't clear
enough for me to be sure. Also, if it is legal, it seems like a good
thing to do in most cases (as a program is unlikely to need to modify
its argv) if one is trying to make full use of _const_.
So, is it legal or not?
-Edward