Mail Archives: djgpp/2001/08/21/15:28:46
> What is the difference, pros, and cons between using exit( ), return 0; and
> abort( ) to exit your program? I have found these three refrenced in the book
> i am using, but there is no comprehensive explanation.
A return from main is exactly the same as calling exit with the same
value. In DJGPP, as in most systems, the routine that calls main just
calls exit if main returns. The only thoughts I have on the
difference is that other functions *must* use return, so a return from
main is consistent, but exit() is for abnormal cases where your
program must exit from elsewhere. Also, if main() returns it can be
called recursively.
abort() is something completely different - it causes the OS to send a
signal to your program, much like if you had pressed Ctrl-C or divided
something by zero (although it's a different signal). Since on most
OS's an unwanted signal causes a core dump, abort() is a way for the
programmer to cause a program to self-destruct in a way that's most
likely to leave debuggable remnants around (namely, a core file).
- Raw text -