From -3288847736203850738 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f78e5,314ebdf2ff957e27 X-Google-Attributes: gidf78e5,public X-Google-ArrivalTime: 2003-04-11 12:50:00 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!cyclone.bc.net!newsfeed.media.kyoto-u.ac.jp!newsfeed.icl.net!newsfeed.fjserv.net!kibo.news.demon.net!mutlu.news.demon.net!demon!mail2news.demon.co.uk!devnull From: nospam42@attbi.com ("Chris Putnam") Newsgroups: comp.std.c++ Subject: Re: Why int main()? Date: Fri, 11 Apr 2003 19:49:59 +0000 (UTC) Organization: Ye 'Ol Disorganized NNTPCache groupie Lines: 56 Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++) Message-ID: <1050087548.757301@hqnntp01.autodesk.com> References: X-Trace: mail2news.demon.co.uk 1050090599 29692 10.0.0.1 (11 Apr 2003 19:49:59 GMT) X-Complaints-To: abuse@demon.net NNTP-Posting-Date: Fri, 11 Apr 2003 19:49:59 +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 1944X7-0007il-00 for mail2news@news.news.demon.net; Fri, 11 Apr 2003 19:49:58 +0000 X-Received: from localhost (localhost [[UNIX: localhost]]) by mulga.cs.mu.OZ.AU id FAA25659; Sat, 12 Apr 2003 05:49:54 +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-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 X-Cache-Post-Path: hqnntp01.autodesk.com!unknown@ciscovpn417.autodesk.com X-Cache: nntpcache 3.0.1 (see http://www.nntpcache.org/) X-Spam-Status: No, hits=-4.8 required=5.0 tests=FROM_ENDS_IN_NUMS,NOSPAM_INC,PRIORITY_NO_NAME, QUOTED_EMAIL_TEXT,REFERENCES,SPAM_PHRASE_01_02 version=2.41 Xref: archiver1.google.com comp.std.c++:18740 I believe this originated in order for UNIX programs to return an error code to the process or shell that launched the program. Among other things, this allows a shell scripting language (such as CSH or Windows batch files) to execute code conditionally depending on the result of a previous command. In my experience, compilers that accept the void main() signature do so by providing a wrapper function to match whatever signature the OS requires. For instance, if the OS needs an int main( int argc, char *argv) signature, the compiler/linker might provide the following wrapper for the OS to call: int wrapper_main( int argc, char *argv) { main(); return 0; } In this case, the compiler arranges for the OS to call wrapper_main() instead. Chris ""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? > > --- > [ 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 ] > --- [ 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 ]