Thread: exit(-3)

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    130

    exit(-3)

    Hi,

    What exit(-3) means. Also, I want to know the difference between it and exit(0), exit(1),exit(-2)

    Thanks

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    I've only seen two uses of exit() in source code.
    > exit(0);
    This is to terminate the program with successful results. This means that the operating system won't bother you about the program crashing or terminating in an unusual way. You should consider using the EXIT_SUCCESS macro instead.

    > exit(EXIT_FAILURE);
    This terminates the program, but the OS will prompt you about the program crashing or terminating in an unusual way. Using numbers in place of the macro is probably fine, but I don't think you should. It's a magic number.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    From the diff man page
    Code:
       An exit status of 0 means no differences were found, 1 means some
    differences were found, and 2 means trouble.
    The only portable return values are
    0 - meaning success
    EXIT_SUCCESS - meaning success
    EXIT_FAILURE - meaning failure

    Anything else depends on how your environment interprets the parameter.

    FWIW, I would stick to small positive integers for indicating varying degrees of success back to the environment.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    1 is also portable (for falure).
    Actually, any non zero Value should be interpreted as a falure.

    Unless you actually use the return value in a script. Then it is meaningfull to have other return values.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    1 is also portable (for falure).
    Actually, any non zero Value should be interpreted as a falure.
    Are you sure? C99 doesnt seem to state what the values of EXIT_SUCCESS and EXIT_FAILURE should be, except that it is implied that EXIT_FAILURE cannot be 0. Although it would be rather inane to do it that way, it seems that EXIT_SUCCESS does not have to be 0.

    From section 7.20.4.3:
    Finally, control is returned to the host environment. If the value of status is zero or
    EXIT_SUCCESS, an implementation-defined form of the status successful termination is
    returned. If the value of status is EXIT_FAILURE, an implementation-defined form
    of the status unsuccessful termination is returned. Otherwise the status returned is
    implementation-defined.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > 1 is also portable (for falure).
    You've obviously never programmed for a VAX then.
    1 is success in that part of the world.

    Not that it matters to your well-written programs which return 0, since the run-time takes care to map that to the implementation "success".
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    ex-DECcie
    Join Date
    Dec 2005
    Posts
    125

    Wow -- the good old days

    Quote Originally Posted by Salem
    > 1 is also portable (for falure).
    You've obviously never programmed for a VAX then.
    1 is success in that part of the world.

    Not that it matters to your well-written programs which return 0, since the run-time takes care to map that to the implementation "success".

    Darn, Salem, you beat me to it.

    I cut my "C teeth" on VAXen, and when I switched to Unix (well, DEC's Ultrix at that time) it felt strange to look for 0 for success and 1 for failure.

    I believe it stayed the same for VMS on Alpha, but lost track of how C progressed in that world shortly thereafter.....
    Mr. Blonde: You ever listen to K-Billy's "Super Sounds of the Seventies" weekend? It's my personal favorite.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Chat Program Help?
    By Paul22000 in forum Networking/Device Communication
    Replies: 9
    Last Post: 02-10-2009, 12:35 AM
  2. Odd memory leaks
    By VirtualAce in forum C++ Programming
    Replies: 11
    Last Post: 05-25-2006, 12:56 AM
  3. Replies: 1
    Last Post: 03-21-2006, 07:52 AM
  4. Dynamic array of pointers
    By csisz3r in forum C Programming
    Replies: 8
    Last Post: 09-25-2005, 02:06 PM
  5. exit() ?
    By smd in forum C++ Programming
    Replies: 4
    Last Post: 06-26-2002, 04:31 PM