why not work

Started by
11 comments, last by Replicon 18 years, 10 months ago
Quote:Original post by Enigma
The return value is not required. The standard declares that a main function which terminates without a return statement implicitly returns zero.

I'm not sure the standard actually says that. Perhaps it does for compatability with very old versions of C. Even so, I'd suggest you should just return anyway as a matter of course.
Advertisement
Quote:Original post by Andrew Russell
I'm not sure the standard actually says that. Perhaps it does for compatability with very old versions of C. Even so, I'd suggest you should just return anyway as a matter of course.

Well, it's definitely in the final draft. I don't own a copy of the final standard, but the final draft states in section 3.6.1, paragraph 5:
Quote:A return statement in main has the effect of leaving the main function (destroying any objects with automatic storage duration) and calling exit with the return value as the argument. If control reaches the end of main without encountering a return statement, the effect is that of executing

return 0;

But your suggestion is, naturally, good advice.

Enigma
Quote:Original post by Enigma
Quote:Original post by Andrew Russell
I'm not sure the standard actually says that. Perhaps it does for compatability with very old versions of C. Even so, I'd suggest you should just return anyway as a matter of course.

Well, it's definitely in the final draft. I don't own a copy of the final standard, but the final draft states in section 3.6.1, paragraph 5:
Quote:A return statement in main has the effect of leaving the main function (destroying any objects with automatic storage duration) and calling exit with the return value as the argument. If control reaches the end of main without encountering a return statement, the effect is that of executing

return 0;

But your suggestion is, naturally, good advice.

Enigma


Hah! I stand corrected! I could have SWORN, though. I'm pretty sure I've used a version of g++ that complained about it, a few years ago.

This topic is closed to new replies.

Advertisement