This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: about main must return "int"
- From: Ben Davis <bndavis at ntlworld dot com>
- To: Amy Lin <alin at itsc dot uah dot edu>,gcc-help at gcc dot gnu dot org
- Date: Mon, 7 Jul 2003 20:59:40 +0100
- Subject: Re: about main must return "int"
- References: <3F09CFAD.8020009@itsc.uah.edu>
- Reply-to: bnd25 at cam dot ac dot uk
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