Originally Posted by
laserlight
Originally Posted by
dwks
Actually, it
should be
Code:
int main(int argc, char *argv[])
but let's not get picky.
What is your reasoning for saying that command line parameters
should be included even when the command line arguments are not used?
Regards,
laserlight
In C, int main() is preferred over int main(void), because the latter means that main takes no parameters, and the code generated for it sometimes assumes this; so when argc and argv are passed to the program by the operating system, the stack can get corrupted.
Or so I hear. Someone else (matsp, I think) explains it better than I.
Anyway, in C++, since int main() and int main(void) are exactly the same -- that is, zero parameters, not unknown parameters -- I thought that the same mechanism might be generated, assuming that no parameters were passed to main(). I don't actually have any proof for this line of reasoning, however.
Another way of putting it: I think the int main() C-style function declarations (with an unknown number of parameters) were dropped from C++ along with function prototypes, like this.
So it would seem that int main() became equivalent to int main(void), and since int main(void) is not completely proper, one shouldn't use either in C++.
Any feedback on this would be appreciated.