From: "John M. Aldrich" Newsgroups: comp.os.msdos.djgpp Subject: Re: New C Programmer Problem Date: Fri, 20 Dec 1996 18:27:13 -0800 Organization: Two pounds of chaos and a pinch of salt Lines: 42 Message-ID: <32BB4B01.6D38@cs.com> References: <32B9BAC8 DOT 5C26 AT bc DOT cybernex DOT net> <19961220 DOT 163011 DOT 8335 DOT 2 DOT chambersb AT juno DOT com> <32BA36D1 DOT 31273C98 AT alcyone DOT com> Reply-To: fighteer AT cs DOT com NNTP-Posting-Host: ppp208.cs.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: Erik Max Francis DJ-Gateway: from newsgroup comp.os.msdos.djgpp Erik Max Francis wrote: > > Actually, the mere declaration > > main() { ... } > > in fact does define main as returning int and taking no parameters. In C, > the default return type of a function when not explicitly specified is int. > Also, when no parameters are explicitly specified, in a definition it is > taken as of taking no parameters. (In a prototype, in C, it doesn't say > anything about the parameter list; in C++, it always means no parameters.) And the version of gcc in DJGPP v2.01 complains about functions that default to int if you compile with -Wall. To me, this indicates potentially unsafe programming techniques which should be avoided. In general, any time the compiler produces a warning about something, you should attempt to get rid of that warning, or you are getting into programming habits which may come back to bite you some day. Likewise, an empty parameter list in C is a throwback to K&R C where you could declare a function to take an unspecified number of parameters. This is _so_ unsafe that the ANSI folks are considering removing it in the next version of the C spec, or so I heard. Just to add a bit to this thread, I deliberately set out to examine what occurs if you declare void main() and do not specify an exit value when your program terminates. The results were not surprising: the return value was essentially random. It changed depending on what command line options I passed to the program and what the program calculated as a result. While this may not be the case with all compilers, it should come across as an absolute and indisputable message: DO NOT USE void main()! l8r -- --------------------------------------------------------------------- | John M. Aldrich, aka Fighteer I | fighteer AT cs DOT com | | Proud owner of what might one | http://www.cs.com/fighteer | | day be a spectacular MUD... | Plan: To make Bill Gates suffer | ---------------------------------------------------------------------