www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/08/21/15:28:46

Date: Tue, 21 Aug 2001 15:28:15 -0400
Message-Id: <200108211928.PAA07064@envy.delorie.com>
X-Authentication-Warning: envy.delorie.com: dj set sender to dj AT envy DOT delorie DOT com using -f
From: DJ Delorie <dj AT delorie DOT com>
To: djgpp AT delorie DOT com
In-reply-to: <3B88F7B3@MailAndNews.com> (message from Ramy Elmeligy on Tue, 21
Aug 2001 14:45:00 -0400)
Subject: Re: exit( ) versus return 0; and abort
References: <3B88F7B3 AT MailAndNews DOT com>
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

> 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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019