abort()

This is a discussion on abort() within the C++ Programming forums, part of the General Programming Boards category; Quick question: Does abort() return anything? It is safer to use then exit(0) I have been told. If I define ...

  1. #1
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475

    abort()

    Quick question:

    Does abort() return anything? It is safer to use then exit(0) I have been told. If I define a function like so:

    Code:
    int terminateMe ( void ) // expected to return an integer
    {
       // do somthing illegal
       
       if ( // bad )
       {
          abort();
        }
    }
    Would abort() return somthing to the OS?

    Thanks in advance.
    I'm just trying to be a better person - My Name Is Earl

  2. #2
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262

  3. #3
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475
    Thanks!
    I'm just trying to be a better person - My Name Is Earl

  4. #4
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,383
    err... abort() returns a system dependent error code to the hosting environment.

    It is safer to use then exit(0) I have been told
    Depends on the circumstances. But usually exit() is better because at least any static objects destructos are called. abort() terminates immediately.

    An explicit call to exit(0) however is probably a bad idea because it implies successful termination, which is not the case since any objects local to the function where exit is called will not have their destructors called. An application that for some reason relies on exit(), should also employ atexit() for proper destruction of local objects.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  5. #5
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,158
    Quote Originally Posted by swgh View Post
    Quick question:

    Does abort() return anything?
    How could a function which aborts, possibly return anything?

    It is safer to use then exit(0) I have been told. If I define a function like so:
    Who told you exit() was unsafe? exit() is fine. abort() will cause an ABNORMAL termination -- i.e., a crash. If all you want to do is terminate, this is not what you want to do.

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    abort() is for critical situations, when your application state is totally hosed, and any further action would just cause more errors. The program will die, no questions asked. The system will get, as was mentioned, an implementation-dependent error code.

    One example: std::terminate() calls abort() and is thus effectively equivalent. std::terminate() is called when the exception handling mechanism encounters a bad problem that it cannot handle.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Exit early (abort) and max # of tests allowed.
    By Zzaacchh in forum C++ Programming
    Replies: 14
    Last Post: 08-18-2008, 02:42 AM
  2. abort() causes a segfault
    By JFonseka in forum C Programming
    Replies: 12
    Last Post: 04-16-2008, 01:40 AM
  3. Abort Procedure
    By incognito in forum Windows Programming
    Replies: 5
    Last Post: 01-02-2004, 08:49 PM
  4. Program abort due to memory problem
    By cazil in forum C++ Programming
    Replies: 5
    Last Post: 01-21-2002, 11:55 AM
  5. questions about new and delete
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 09-07-2001, 01:48 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21