delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/02/25/00:46:58

Message-Id: <3.0.6.32.19990225004405.008cf440@pop.globalserve.net>
X-Sender: derbyshire AT pop DOT globalserve DOT net
X-Mailer: QUALCOMM Windows Eudora Light Version 3.0.6 (32)
Date: Thu, 25 Feb 1999 00:44:05 -0500
To: djgpp AT delorie DOT com
From: Paul Derbyshire <pderbysh AT usa DOT net>
Subject: Re: Duh
In-Reply-To: <36CEADC5.7422E668@xyz.net>
References: <36CCA146 DOT 8BCD8720 AT mail DOT globalserve DOT net>
<7alvgv$25g$1 AT news7 DOT svr DOT pol DOT co DOT uk>
Mime-Version: 1.0
Reply-To: djgpp AT delorie DOT com

At 12:42 PM 2/20/99 +0000, you wrote:
>    It should work either way though,  at least this code works just fine
>fore me:
>#include <iostream.h>
>
>main ()
>{
>cout<<"hey hey\n";
>}

foo.cc: 3: warning: return type of 'main' defaults to 'int'
foo.cc: 6: warning: return with no value in function not returning 'void'

(Strangely enough egcs fails to emit either of these with -Wall, but it
should and IIRC gcc 2.8.x does if you define a function like that... egcs
just silently outputs an 891 byte .o file as though that were a well-formed
program!)

>> #include <iostream.h>
>>
>> void main()
>> {
>>     cout<<"Hello world"<endl;
>>     return 0;
>> }
>
>I havn't done a whole bunch of progremming in C++ so I was wondering why you
>declared main as void and then have it return a value?

Because he made a mistake :-) It should return 'int'.

-- 
   .*.  "Clouds are not spheres, mountains are not cones, coastlines are not
-()  <  circles, and bark is not smooth, nor does lightning travel in a
   `*'  straight line."    -------------------------------------------------
        -- B. Mandelbrot  |http://surf.to/pgd.net
_____________________ ____|________     Paul Derbyshire     pderbysh AT usa DOT net
Programmer & Humanist|ICQ: 10423848|

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019