Boost logo

Boost :

From: James Dennett (jdennett_at_[hidden])
Date: 2001-10-08 20:09:36


deansturtevant_at_[hidden] wrote:

>>>3) VC++ 6.0 gives a bothersome warning if no "return 0"
>>> is at the end of main.
>>>
>>Well, that's just a VC++ problem. The code is valid and shouldn't
>>produce a diagnostic, so I'm not going to change it.
>>
>
>IMHO, the standard is the one with the problem. Why is it that all
>functions that return int must return int except for 'main'?
>
An odd convenience allowed to main, as it is the only
user-defined function for which the language specifies
a meaningful return value (0, or EXIT_SUCCESS).

> Correct
>me if I am mistaken, but it's because prior to standardization, main
>could return void, and changing existing code to return 0 was
>considered too much of a burden.
>
You're mistaken. void main has never been legal, even back to
the 1989 C Standard and before.

> I feel proper coding practice is to
>make the return explicit, regardless of whether the standard says
>it's not necessary.
>
It's certainly legal and consistent to do so, and does stop
retarded compilers from issuing warnings. It also stops
complaints from developers who don't know the rules.
For toy examples I tend to elide the "return 0;" but for
production code I include it, often with a comment to
(a) say why it's there, and that I know it's optional, and
(b) stop developers from removing it, because I know
that other developers would be puzzled by its absence.
Sad but true.

-- James Dennett


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk