Mail Archives: djgpp/1998/08/15/11:15:35
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 |
---------------------------------------------------------------------
- Raw text -