Recently I noticed a question where a long time user edit the void main()
in the OP's code to int main()
. I left a comment asking how did he know that is not using void main()
? I got a reply back from the editor
[...]It would be really bad teaching to let it pass by in SO example code (except where it is the point of the code), so please do fix that wherever you see it.[...]
Now I get that void main()
is not standard in C++, it never has been and I do not think it ever will be. I personally point that out to the OP in a comment and normally I link to What should main() return in C and C++?. The editor did have that in their comment
You might also admonish the OP about it. When you have the time.
Which I agree with but if the code is changed to int main()
then the comment looks out of place as there is no void main()
in the code anymore.
So do we really want to change the OP's code in this case or should we leave it alone and politely inform the user that they should not be using void main()
?
I disagree with the dupe closure. The dupe states that the edit should not change the intent of the OP. That is what I am trying to figure out in this question. Does changing void main() to int main() which has no effect on the code except to make it compile on compliant compilers changing the intent or not and if it does not then should we still do it or not.
void main()
but the question now showsint main()
and it was not edited by the OP.int main
is a problem because it's not accepted by many compilers. This means that it (1) teaches readers an Evil(tm) practice, and (2) makes it less straightforward for those who answer to try out code: withvoid main
it has to be modified to try it, unless one happens to use a compiler that accepts it.int main
is a problem because it's not accepted by many compilers. is completely false. I brought this issue to meta as I do not think it is correct to change the OP's code as it changes its behavior.#include <string>
when someone does not but it compiles on their platform as one of their other includes does include<string>
?void
return type (supported in VC++), did not bother to include areturn
statement in this method that is now supposed to return anint
. Yet another reason for not editing code is that it's a lot easier to make a harmful mistake when one does, as so aptly demonstrated by that editor.void main
compiles) and system ("pause") suggests Windows as well. But even then, I think any reasonable developer would know how to resolve the problem withvoid main
. It's not like the OP even provided a compilable program. Anyone would have realized it was missing ausing namespace
and a couple of includes. I've seen other users bring the issue withvoid main
up, but it is generally done as a comment, or if someone answers the question they bring it up there as a side note.void main
is not standard but not having the return is.