about main must return "int"
Ben Davis
bndavis@ntlworld.com
Mon Jul 7 20:01:00 GMT 2003
On Monday 7 July 2003 8:53 pm, Amy Lin wrote:
> Hi, I am new with this list, and I need your help.
>
> After installing Redhat 8.0 which has gcc 3.2, I ran into a problem when
> recompiling a project. with c++. It errors out on "main" must return
> "int". All my old codes with "void" main. I used c++ from egcs-1.1-2
> (redhat 7.3) and it was no problem there. My question is: Is this a bug
> of gcc 3.2, or this is a permanent change and I will have to change my
> codes?
I can't answer your question about how the GCC project is handling this
mistake, but I can tell you that main should return int and your code is
wrong if your main function returns void. So yes, you should change your
code.
The use of the return value is to let the parent process know if your program
did what it was supposed to do successfully. For instance, GCC itself will
return zero if it was capable of producing valid output. This can be used by
GNU Make; if GCC returns nonzero, GNU Make will know that something went
wrong, and it will not try to complete the build.
Ben
More information about the Gcc-help
mailing list