Any way to get g++ to warn about missing return in main
Bill Priest
priestwilliaml@yahoo.com
Fri Jan 11 11:04:00 GMT 2002
On Fri, 11 Jan 2002 12:03:35 -0600
"John Love-Jensen" <eljay@adobe.com> wrote:
> Hi Bill,
>
> I assume your second example was supposed to be "g++ ..." instead of "gcc
> ...".
Actually since the extension is .cc it uses g++ by default.
>
> As per the C++ specification, it is legal and valid C++ code to have main()
> drop off the end without a return. The compiler is burdened with putting an
> implicit "return 0;" in the code on the (lazy) programmer's behalf.
I understand that it is legal C++ code; I'd just like for g++ to warn about it
just like gcc does IFF I set a compiler switch warning to catch it (ie. it seems
like -Wmain-return-type).
Of course for this simple example I gave it is obvious that the compiler adding
a return of is is correct; this might not always be the case and without an
explicit statement in the code the compiler can't be sure that is what I intended.
I'm not looking to change the semantics of inserting the default; I'm just looking
for a way for me to be reminded that it is missing in case I don't want the default.
Thanks for the response,
Bill
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
More information about the Gcc-help
mailing list