Thread: abort()

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

    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.
    Double Helix STL

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

  3. #3
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    Thanks!
    Double Helix STL

  4. #4
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    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.
    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
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    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,895
    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, 09:49 PM
  4. Program abort due to memory problem
    By cazil in forum C++ Programming
    Replies: 5
    Last Post: 01-21-2002, 12:55 PM
  5. questions about new and delete
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 09-07-2001, 01:48 PM