c++ - Should return 0; be avoided in main()? -


i know current c++ standard special cases main falling off end has same effect return 0; rather undefined behavior.

i surprised see an example @ codereview responses not pointed out including final return 0; optional, went far remove original code.

thus prompts question — considered bad style make return 0; explicit @ end of main? rationale or against?

i'll take wild stab in dark here , people fall 2 camps:

  • those remove line think redundant , such code should removed brevity

  • those add line think makes return value clear , unambiguous lesser coders.

personally, tend write meaningful return statement in main in production code (if because production mains tend contain code paths end returning other 0, in exception handlers), although wouldn't bother trivial main never returns else; example, don't think i've ever done in, say, coliru post stack overflow demonstration.

some it's absurd alter codebase flip between these 2 states, arguments both weak in grand scheme of things, , such personal choice not worth risking introduction of bugs.

but i'd depends entirely on environment like. if you're halfway through release cycle, of course you're going make code maintenance improvements , style adjustments: best time avoid accruing technical debt, , absolutely want that. if you're planning make change directly on production server, or in version control 1 week before big release, you're out of mind.

(hopefully policies prevent such madness anyway. code freeze, yes? no changes production, right?)

so, although goes without saying the underlying choice highly subjective, can quantify risk/benefit of enforcing such choice after-the-fact.

but never mind real life, on code review? well, have no idea; you'd have ask them. personally, on specific examples, have removed too, albeit written caveat purely style choice. whether purely style changes appropriate on code review question code review meta.


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -