robatino's statement was with respect to the global main() function, which returns an int, and which specifically returns 0 if control does not reach a return statement within it.Quote:
At best it returns void. Not 0.
Printable View
robatino's statement was with respect to the global main() function, which returns an int, and which specifically returns 0 if control does not reach a return statement within it.Quote:
At best it returns void. Not 0.
Ah. I'm too distracted it seems. Need a rest.
There have been buggy compilers from time to time that were so broken that they required a return at the end of each function, even those that didn't return anything.
But nowadays, I would personally consider it a very strange habit if a programmer put an explicit return at the end of each function. Waste of a line and 7 characters, and it's so easy to accidentally put it in the wrong place, at least when later rearranging a function.
@vart: But again, you can use if(a != b) and put your code in the if() block without using an empty return.
That's true, Des, but that can get very messy if there are a large number of conditions where you want to short-circuit out.
Also, if there are a large number of lines after the condition, they all have to be indented an extra level, which takes up more space than a single extra return, and I think makes the code harder to understand.Quote:
Originally Posted by XSquared