From 5166076690341664858
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,314ebdf2ff957e27
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2003-04-11 11:49:30 PST
Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!kibo.news.demon.net!mutlu.news.demon.net!demon!mail2news.demon.co.uk!devnull
From: rmaddox@isicns.com (Randy Maddox)
Newsgroups: comp.std.c++
Subject: Re: Why int main()?
Date: Fri, 11 Apr 2003 18:49:29 +0000 (UTC)
Organization: http://groups.google.com/
Lines: 44
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <8c8b368d.0304110456.32746199@posting.google.com>
References: <Qbvla.955$5Z2.28625@newsfep1-win.server.ntli.net>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: mail2news.demon.co.uk 1050086970 29346 10.0.0.1 (11 Apr 2003 18:49:30 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Fri, 11 Apr 2003 18:49:30 +0000 (UTC)
X-Received: from mulga.cs.mu.oz.au ([128.250.1.22])
	by news.demon.co.uk with esmtp (Exim 4.12)
	id 1943aa-0007dB-00
	for mail2news@news.news.demon.net; Fri, 11 Apr 2003 18:49:28 +0000
X-Received: from localhost (localhost [[UNIX: localhost]]) by mulga.cs.mu.OZ.AU
	id EAA21427; Sat, 12 Apr 2003 04:49:24 +1000 (EST)
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Path: comp-std-cpp-robomod!not-for-mail
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Delivered-To: std-c++@ucar.edu
X-Newsgroups: comp.std.c++
X-NNTP-Posting-Date: 11 Apr 2003 12:56:16 GMT
X-Spam-Status: No, hits=-8.4 required=5.0
	tests=NOSPAM_INC,QUOTED_EMAIL_TEXT,REFERENCES,SPAM_PHRASE_00_01
	version=2.41
Xref: archiver1.google.com comp.std.c++:18732

Huw@Tesco.net ("Huw Ford") wrote in message news:<Qbvla.955$5Z2.28625@newsfep1-win.server.ntli.net>...
> Why was main defined as returning int?
> A lot of my work has been with embedded devices where the program never
> returns from main.
> For example main would look like this;
> 
> int main(int argc,char* argv[])
> {
>     while(true)
>     {
>         DoThings();
>     };
>  return 0;
> }
> 
> The return value should never be reached and even if main did return there
> would be nothing that could be done with the return value.
> A lot of compilers will accept "void main()" so why must main return an int?
> 

Because that's what the C++ Standard specifies in subclause 3.6.1?

Seriously, although your situation is different, many applications do
need to return a value of some type to the OS to let the user know
whether the program was succesful or had a problem.  Since this is
such a common need a standard way of supplying such a value had to be
specified.  Obviously if every program had its own way of reporting
its termination status there would be no way for that to work
portably.  So the writers of the C++ Standard chose the same behavior
as was already long specified for C programs as the way to provide
this commonly needed functionality.

Compilers that accept void main() are providing a non-standard
extension.  It may work fine for you in a particular case, but it is
not standard behavior and you cannot expect it to be portable.

Randy.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]



