From: "John M. Aldrich" Newsgroups: comp.os.msdos.djgpp Subject: Re: 2 quick questions Date: Sat, 15 Aug 1998 10:28:58 -0400 Organization: Two pounds of chaos and a pinch of salt. Lines: 32 Message-ID: <35D59B2A.419D2C70@cs.net> References: <35D4F001 DOT 4A3E2B2D AT xyz DOT net> <35D4F431 DOT F5D956B8 AT cs DOT net> <35D525C5 DOT 9B79BFB AT xyz DOT net> NNTP-Posting-Host: ppp141.cs.net 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 Bjorn Hansen wrote: > > My programs that are successful often return a different exit code. When > they fail I think they usually return 255. I don't put anything like > return(0); at the end. should I do this? Is there anything else an exit > code tells you besides if the program was successful. It seems like it must > since it does not just return a 0 or a 1. If you declare a function to have a return value, you need a 'return' statement in it. For DJGPP programs, at least, an exit code of 255 occurs on abnormal program termination, such as a crash (SIGSEGV, etc.) or user break (Ctrl-C, Ctrl-Break). If you terminate the program yourself, you can determine what exit code it produces. There's no rule except that zero indicates success and nonzero indicates failure. In a complex program, you might have different exit codes indicate different types of errors, and document them so that a user can take advantage of them. (For an example of this, see my DJVERIFY program on my web site below.) One other use of exit codes is for programs that perform calculations or output a range of values for a batch file or parent program to read. Examples include the 'choice' utility that comes with DOS 6.x and higher, some calculator apps, etc. -- --------------------------------------------------------------------- | John M. Aldrich | "Waking a person unnecessarily | | aka Fighteer I | should not be considered a capital | | mailto:fighteer AT cs DOT net | crime. For a first offense, that | | http://www.cs.net/fighteer/| is." - Lazarus Long | ---------------------------------------------------------------------