Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!uwm.edu!cs.utexas.edu!asuvax!noao!amethyst!arizona!dave From: dave@cs.arizona.edu (Dave P. Schaumann) Newsgroups: comp.lang.c Subject: Re: Is void main(void) ANSI standard?? Message-ID: <1135@caslon.cs.arizona.edu> Date: 12 Mar 91 01:35:41 GMT References: <1991Mar11.085439.1@sysjj.mdcbbs.com> Organization: U of Arizona CS Dept, Tucson Lines: 30 In article <1991Mar11.085439.1@sysjj.mdcbbs.com> hooverm@sysjj.mdcbbs.com (SQUID 6 on the DARK side) writes: >When a program is compiled/linked and there is no value returned to main, >certain platforms will return a warning message stating that this function >doesn't return a value. > >I thought that by declaring: void main(void) that I would get around this. > >Is this ANSI standard? If it is valid, why doesn't my SUN SparcStation like >it? [...] Well, first you have to understant that one of the oddities of C (IMHO) is that if you declare a function like this: main() { ... } The return type becomes "int" by implication. This is probably not the best idea in the world, but the backward-compatability crowd wouldn't have it any other way. Declaring main as a void is *not* a good idea. Many systems take the value returned by main() to be the "exit status" of the program. (Usually, a value of 0 means all is well, and a non-0 value means some kind of error has occurred). If you don't really care about this, just put a return 0 ; (or exit(0)), and all should be well. Of course, you should see another thread appearing in this group for a discussion about return values under VMS. -- Dave Schaumann | dave@cs.arizona.edu | Short .sig's rule!