Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!ccu.umanitoba.ca!herald.usask.ca!alberta!brazeau.ucs.ualberta.ca!unixg.ubc.ca!ubc-cs!uw-beaver!cornell!batcomputer!caen!uakari.primate.wisc.edu!samsung!olivea!uunet!mcsun!ukc!strath-cs!gdt!exspes From: exspes@gdr.bath.ac.uk (P E Smee) Newsgroups: comp.std.c Subject: Re: Must main return a value? Message-ID: <1991Jun28.141949.5266@gdr.bath.ac.uk> Date: 28 Jun 91 14:19:49 GMT References: <7830001@hpwrce.HP.COM> Reply-To: P.Smee@bristol.ac.uk (Paul Smee) Organization: University of Bristol c/o University of Bath Lines: 29 In article <7830001@hpwrce.HP.COM> walterm@hpwrce.HP.COM (Walter Murray) writes: >Is the following program strictly conforming? > > int main(void) { return; } > >Many people have written that the main function must return a value. >I can't find such a requirement in the Standard. I have read 2.1.2.2.3 >and 3.6.6.4. Am I missing something? Yep. The construct you used, 'int main (...' declares main to be a function which returns an int. You have declared it as returning a value, and then not returned a value of the type specified. Speaking pedantically, that's a prima facie violation. In practice, since return from main() generally throws you out of your C-program environment, and back into your native operating system environment, whether or not it makes any difference depends on your OS. Many OSes expect progs to return status codes -- especially progs which have been declared to return status codes. If you don't return one, the results will be OS-dependent but can range the full gamut from unpleasantly surprising to unpleasantly mysterious. If you're really unlucky, your failure to return the value you promised won't make any difference at all -- until next year, when you've got to move the prog to another OS platform and have forgotten what you did. -- Paul Smee, Computing Service, University of Bristol, Bristol BS8 1UD, UK P.Smee@bristol.ac.uk - ..!uunet!ukc!bsmail!p.smee - Tel +44 272 303132