Timeline for Should we change "void main()" to "int main()" in the OP's code?
Current License: CC BY-SA 3.0
37 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
May 23, 2017 at 12:38 | history | edited | CommunityBot |
replaced http://stackoverflow.com/ with https://stackoverflow.com/
|
|
Aug 25, 2016 at 18:32 | vote | accept | NathanOliver | ||
Apr 2, 2016 at 15:50 | history | reopened |
NathanOliver jscs Brad LarsonMod discussion Users with the discussion badge or a synonym can single-handedly close discussion questions as duplicates and reopen them as needed. |
||
Mar 31, 2016 at 15:28 | review | Reopen votes | |||
Mar 31, 2016 at 16:16 | |||||
Mar 31, 2016 at 3:30 | history | closed |
Peter Duniho Luke Glorfindel HaveNoDisplayName ketan |
Duplicate of When should I make edits to code? | |
Mar 30, 2016 at 21:44 | history | edited | NathanOliver | CC BY-SA 3.0 |
added 368 characters in body
|
Mar 30, 2016 at 21:27 | comment | added | Peter Duniho |
Ah, okay. You're right...I forgot that main() was treated specially by the specification. Still, I find functions that return values (even main() ) and which don't have return statements to be abhorrent. At the same time, the code as posted was fine, given that the OP was using a compiler that allows void main() .
|
|
Mar 30, 2016 at 21:23 | comment | added | NathanOliver |
@PeterDuniho Whether the return statement is required or not depends on compiler settings No it does not. The standard guarantees that not having a return statement in main is okay. That is not a setting but an aspect of being standard compliant. In any case, an int main() method without a return statement is way worse than a void main() No again. void main is not standard but not having the return is.
|
|
Mar 30, 2016 at 21:13 | comment | added | Michael Petch |
@NathanOliver : It doesn't, and I am with you. I think it is clear that the OP was using an MSVC++ compiler (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 with void main . It's not like the OP even provided a compilable program. Anyone would have realized it was missing a using namespace and a couple of includes. I've seen other users bring the issue with void 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.
|
|
Mar 30, 2016 at 21:10 | review | Close votes | |||
Mar 31, 2016 at 3:30 | |||||
Mar 30, 2016 at 21:10 | answer | added | user1531971 | timeline score: -8 | |
Mar 30, 2016 at 21:09 | comment | added | NathanOliver |
@PeterDuniho You do not need return 0; at the end of main so it is okay he didn't add it as it adds nothing. reaching the end of main without a return is an implicit return 0;
|
|
Mar 30, 2016 at 21:07 | comment | added | Peter Duniho |
By the way, I looked at the edit in question. I find it ironic that the person who made the edit, who is apparently so bothered by the use of the non-standard void return type (supported in VC++), did not bother to include a return statement in this method that is now supposed to return an int . 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.
|
|
Mar 30, 2016 at 21:01 | comment | added | Peter Duniho | The only person who can answer that is the OP of the question. You should be asking that person, not Meta. You may propose the change in comments. But editing the actual question without first verifying your edit doesn't change what the OP intended to post is simply wrong. And that's been addressed, in the proposed duplicate question. | |
Mar 30, 2016 at 20:55 | comment | added | NathanOliver |
@PeterDuniho That is what I am trying to figure out. 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.
|
|
Mar 30, 2016 at 20:49 | comment | added | Peter Duniho | Edits are expected to not change the author's intent. This includes not changing the semantics of the code. See the proposed duplicate question, which specifically calls out "Don't change the code logic or functionality". Even if the code is bad, it is what the author posted, and should not be changed. | |
Mar 30, 2016 at 20:29 | answer | added | Trisped | timeline score: 3 | |
Mar 30, 2016 at 20:25 | answer | added | Barry | timeline score: 7 | |
Mar 30, 2016 at 20:13 | answer | added | Yakk - Adam Nevraumont | timeline score: 9 | |
Mar 30, 2016 at 19:40 | answer | added | ForceBru | timeline score: -13 | |
Mar 30, 2016 at 19:34 | comment | added | underscore_d | is your argument seriously that we should edit questions to constitute good examples? really? you've seen how trivial most of them are, right? downvote or comment and move on. SO should be judged by its answers, their votes, and critical thought above both. trying to bend all questions to be useful examples in and of themselves is a real waste of time, not only for the other reasons given, but because most of them are not good examples, by definition... otherwise there'd be no question to ask. | |
Mar 30, 2016 at 16:24 | comment | added | Cheers and hth. - Alf | @NathanOliver: I would not do that. For one, because with headers there is a possible effect on the rest of the code, and secondly, because it (in my opinion) doesn't help anyone. Formatting and other non-meaning-changing editing is OK, as I see it. | |
Mar 30, 2016 at 16:21 | comment | added | NathanOliver |
@Cheersandhth.-Alf Since when do we do that? Does that also mean we should add #include <string> when someone does not but it compiles on their platform as one of their other includes does include <string> ?
|
|
Mar 30, 2016 at 16:16 | comment | added | Cheers and hth. - Alf | "it changes its behavior" is correct: it makes the code compile on C++ compilers in general. That is not a reason to not do it. It's a reason to do it. Except for questions where that is precisely the (or one) issue. | |
Mar 30, 2016 at 16:14 | comment | added | Cheers and hth. - Alf |
void main , sorry for the typo. It's a bit antagonistic to call a typo "completely false", don't you think? Your statement that I corrected was ""you cannot have static free functions", quoted in my comment about it. Your original comment is deleted.
|
|
Mar 30, 2016 at 16:12 | comment | added | NathanOliver | If you are talking about the static free functions I admitted I was wrong and removed the comment. | |
Mar 30, 2016 at 16:11 | comment | added | NathanOliver |
@Cheersandhth.-Alf What statement of mine did you correct? If anything your 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.
|
|
Mar 30, 2016 at 16:08 | comment | added | Cheers and hth. - Alf | It's just a few days since last I pointed out an error of someone, and the someone started a silly edit war, postulated an absurd interpretation of my question, and posted about it on meta. Likewise, just after correcting one of Nathan's statements, he construes an issue that doesn't exist, and posts about it on meta. I can't help but notice a pattern. | |
Mar 30, 2016 at 16:05 | comment | added | Cheers and hth. - Alf |
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: with void main it has to be modified to try it, unless one happens to use a compiler that accepts it.
|
|
Mar 30, 2016 at 14:47 | comment | added | Hans Passant | What the OP is actually using in his program is completely irrelevant, the question was not about getting the wrong process exit code. The tedious comments are obsolete so flag them that way. | |
Mar 30, 2016 at 14:32 | comment | added | NathanOliver |
@HansPassant But the comment isn't obsolete. Most likely the OP is still using void main() but the question now shows int main() and it was not edited by the OP.
|
|
Mar 30, 2016 at 14:30 | comment | added | Hans Passant | Simply flag obsolete comments as "Obsolete". | |
Mar 30, 2016 at 13:53 | answer | added | Seth | timeline score: 16 | |
Mar 30, 2016 at 13:17 | comment | added | Alex Tartan | On a "suggested edit review", that would get rejected as an "attempt to reply" comment. And for good reason. Code shouldn't be changed. | |
Mar 30, 2016 at 13:02 | comment | added | Maroun | I don't like to edit someone's code if it's not a (very) clear typo (even if my edit improves or fix the "bad" code). | |
Mar 30, 2016 at 12:59 | history | edited | NathanOliver | CC BY-SA 3.0 |
edited body
|
Mar 30, 2016 at 12:51 | history | asked | NathanOliver | CC BY-SA 3.0 |