public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: about main must return "int"
@ 2003-07-07 21:50 Keen Wayne A Contr AFRL/MNGG
  2003-07-09 18:24 ` Amy Lin
  0 siblings, 1 reply; 6+ messages in thread
From: Keen Wayne A Contr AFRL/MNGG @ 2003-07-07 21:50 UTC (permalink / raw)
  To: 'gcc-help@gcc.gnu.org'

You might find this link of some interest:

http://www.research.att.com/~bs/bs_faq2.html#void-main

Wayne Keen

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: about main must return "int"
  2003-07-07 21:50 about main must return "int" Keen Wayne A Contr AFRL/MNGG
@ 2003-07-09 18:24 ` Amy Lin
  0 siblings, 0 replies; 6+ messages in thread
From: Amy Lin @ 2003-07-09 18:24 UTC (permalink / raw)
  To: 'gcc-help@gcc.gnu.org'


Just want to thank you all for the reply regarding my question.  That's 
really help. :-)

-Amy



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: about main must return "int"
  2003-07-07 19:53 Amy Lin
  2003-07-07 20:01 ` Ben Davis
  2003-07-07 20:12 ` David Odin
@ 2003-07-07 20:17 ` LLeweLLyn Reese
  2 siblings, 0 replies; 6+ messages in thread
From: LLeweLLyn Reese @ 2003-07-07 20:17 UTC (permalink / raw)
  To: Amy Lin; +Cc: gcc-help

Amy Lin <alin@itsc.uah.edu> writes:

> 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

The C++ standard does not allow main to return anything other than
    int. gcc aims for (but not does not yet achieve) full conformance.

> (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?

You will have to change your code. 'void main' was never portable
    anyway. 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: about main must return "int"
  2003-07-07 19:53 Amy Lin
  2003-07-07 20:01 ` Ben Davis
@ 2003-07-07 20:12 ` David Odin
  2003-07-07 20:17 ` LLeweLLyn Reese
  2 siblings, 0 replies; 6+ messages in thread
From: David Odin @ 2003-07-07 20:12 UTC (permalink / raw)
  To: Amy Lin; +Cc: gcc-help

On Mon, Jul 07, 2003 at 02:53:17PM -0500, 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?
> 
  In C and C++, the main() function _has_ to return an int, which will
be used by the shell which run the program.  However, with C++, the
return statement isn't mandatory anymore, and a main() function with a
missing return statement will silently return 0.

   HTH,

        DindinX

-- 
david@dindinx.org
main(a,b){for(;a=223&getchar()+1;putchar(32))if(a>64&a<92)for(b=0,a=
"Xzjtpnd~xFTvHhDfRl|P\\^LZJr"[a-66];(a/=2)>1;b+=a%2)b&&putchar(45+a%2);}

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: about main must return "int"
  2003-07-07 19:53 Amy Lin
@ 2003-07-07 20:01 ` Ben Davis
  2003-07-07 20:12 ` David Odin
  2003-07-07 20:17 ` LLeweLLyn Reese
  2 siblings, 0 replies; 6+ messages in thread
From: Ben Davis @ 2003-07-07 20:01 UTC (permalink / raw)
  To: Amy Lin, gcc-help

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* about main must return "int"
@ 2003-07-07 19:53 Amy Lin
  2003-07-07 20:01 ` Ben Davis
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Amy Lin @ 2003-07-07 19:53 UTC (permalink / raw)
  To: gcc-help

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?

Thank you very much.

-Amy


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2003-07-09 18:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-07 21:50 about main must return "int" Keen Wayne A Contr AFRL/MNGG
2003-07-09 18:24 ` Amy Lin
  -- strict thread matches above, loose matches on Subject: below --
2003-07-07 19:53 Amy Lin
2003-07-07 20:01 ` Ben Davis
2003-07-07 20:12 ` David Odin
2003-07-07 20:17 ` LLeweLLyn Reese

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).