From: "A. Sinan Unur" Newsgroups: comp.os.msdos.djgpp Subject: Re: void main ? Date: Sat, 05 Jul 1997 13:17:58 -0400 Organization: Cornell University http://www.cornell.edu Lines: 55 Sender: asu1 AT cornell DOT edu (Verified) Message-ID: <33BE81C6.7F87@cornell.edu> References: <97Jul5.152902gmt+0100 DOT 16642 AT internet01 DOT amc DOT de> Reply-To: asu1 AT cornell DOT edu NNTP-Posting-Host: cu-dialup-0002.cit.cornell.edu Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Chris Croughton wrote: > > There is a lot of code which does not need the return > value of main ever, because main should never return. > This includes all embedded software (mobile phones being > the most ubiquitous example, since all phone software > I've seen is written in C/C++). The only case where > there's likely to be unexpected action on the return code > is if it's called from a makefile, and the code most > people write is unlikely to be called like that (ever > seen a game called from a makefile?). If a person is > writing code for use with make or shell scripts which > test the return value then it's up to them to make it > return something sensible. However, just forcing a > return of some kind doesn't make the value meaningful... please read the C faq and the references contained there: 11.12: Can I declare main() as void, to shut off these annoying "main returns no value" messages? A: No. main() must be declared as returning an int, and as taking either zero or two arguments, of the appropriate types. If you're calling exit() but still getting warnings, you may have to insert a redundant return statement (or use some kind of "not reached" directive, if available). Declaring a function as void does not merely shut off or rearrange warnings: it may also result in a different function call/return sequence, incompatible with what the caller (in main's case, the C run-time startup code) expects. (Note that this discussion of main() pertains only to "hosted" implementations; none of it applies to "freestanding" implementations, which may not even have main(). However, freestanding implementations are comparatively rare, and if you're using one, you probably know it. If you've never heard of the distinction, you're probably using a hosted implementation, and the above rules apply.) References: ANSI Sec. 2.1.2.2.1, Sec. F.5.1; ISO Sec. 5.1.2.2.1, Sec. G.5.1; H&S Sec. 20.1 p. 416; CT&P Sec. 3.10 pp. 50-51. -- Sinan ******************************************************************* A. Sinan Unur WWWWWW |--O+O mailto:sinan DOT unur AT cornell DOT edu C ^ http://www.people.cornell.edu/pages/asu1/ \ ~/ Unsolicited e-mail is _not_ welcome, and will be billed for. *******************************************************************