what is the meaning of exit()?

Discussion in 'C Programming' started by nick, Oct 13, 2005.

  1. nick

    nick Guest

    such as exit(0),exit(1)

    can i put any no. in the bracket?
    what is their meanings?

    nick, Oct 13, 2005
    1. Advertisements

  2. Charles M. Reinke, Oct 13, 2005
    1. Advertisements

  3. Yes, you can.
    Standard C defines only three valid values:

    0 and EXIT_SUCCESS

    mean that the program completed successfully.


    indicates a failure.

    The EXIT_* macros are defined in stdlib.h.

    For more information, see


    A. Sinan Unur, Oct 13, 2005
  4. A. Sinan Unur, Oct 13, 2005
  5. Apparently they are: http://ccs.ucsd.edu/c/crit_pb.html.

    Also note that http://www.dinkumware.com/refxc.html refers to C99, whereas
    the link I provided is for C89/90, I believe (e.g. the lack of <stdbool.h>,
    etc.). Both are authored/copyrighted by P. J. Plauger, though.

    Charles M. Reinke, Oct 13, 2005
  6. nick

    SM Ryan Guest

    # such as exit(0),exit(1)
    # can i put any no. in the bracket?
    # what is their meanings?

    The number is made available to the operating system, to use or ignore
    as the operating system sees fit.

    On unix, it's returned by the wait* functions, are assigned to $? in
    Bourne shell.
    SM Ryan, Oct 13, 2005
  7. nick

    Mabden Guest

    Whatever you want. Zero means success. Anything else is considered an
    error. You get to make up the error codes. It's YOUR program.
    Mabden, Oct 28, 2005
  8. That's incorrect. Either 0 or EXIT_SUCCESS means success.
    EXIT_FAILURE means failure. Anything else is system-specific.

    The convention of any non-zero status denoting failure is specific to
    Unix (and possibly some other systems).

    It's very common to use exit(1) to indicate failure, but it's not
    portable; for example, it indicates success on VMS.
    Keith Thompson, Oct 28, 2005
  9. With a caveat.
    That part is just rubbish. It is *not* true that anything else is
    considered [to signal] an error. There are 3 values with defined
    meanings: 0, EXIT_SUCCESS, and EXIT_FAILURE.
    exit(0) and exit(EXIT_SUCCESS) both return an implementation-defined
    form of the status 'successful termination' (although EXIT_SUCCESS need
    not have the value 0). exit(EXIT_FAILURE)
    returns an implementation-defined form of the status 'unsuccessful
    Any other value has no standardly defined meaning but is
    implementation-defined. That implementation-definded meaning need not be

    Please don't lie to the newbies. And if you don't know the answer, just
    resist your irresistible urge to type bullshit.
    Martin Ambuhl, Oct 28, 2005
  10. nick

    Jordan Abel Guest

    Incorrect. For example, on many systems an attempt to exit with the
    code 256 [or any multiple of such] will result in reporting a
    "success" [0 mod 256] to the operating system.

    Only EXIT_FAILURE is guaranteed by the standard. On POSIX and
    Windows you are guaranteed one byte.
    Jordan Abel, Oct 28, 2005
  11. Calm down. Bad week to stop your meds.
    Kenny McCormack, Oct 28, 2005
  12. So, you'd think. But you are about to be surprised by the thread-hijackers
    of this group...
    Kenny McCormack, Oct 28, 2005
  13. nick

    Jordan Abel Guest

    He's simply incorrect though - codes other than 0, EXIT_SUCCESS and
    EXIT_FAILURE aren't guaranteed to indicate failure - in particular,
    an exit code of 256 will usually be read as success
    indistinguishable from 0.
    Jordan Abel, Oct 28, 2005
  14. (To no one in particular)

    See what I mean?

    (I think you guys need to look up the phrase "SEP" - I believe it is
    a Douglas Adams thing)
    Kenny McCormack, Oct 28, 2005
  15. There is nothing in my post to indicate that I was not perfectly calm in
    writing it or that I am in any need of medication. Your post, however,
    shows a willingness to make judgments with no facts and to condemn
    reasonable statements. Your Frisk-like diagnoses indicate that you need
    to serious seek help.
    Martin Ambuhl, Oct 28, 2005
  16. We start with the fact that Mabden in wrong here
    (don't stop the presses).

    If you (or nick or anyone else) take his advice it is not somebody
    problem it is yours.

    -William Hughes
    William Hughes, Oct 28, 2005
  17. nick

    Jordan Abel Guest


    is this a success or an error? 256 is a nice round number, if he
    didn't know this issue he might have picked it - maybe to encode a
    set of flags in the exit code. I choose 256 because unlike most
    other possibilities, it most likely _won't_ "work for him".

    (who else's problem do you claim this is?)
    Jordan Abel, Oct 28, 2005
  18. Kenny, you are being a deliberate troll. Mabden posted seriously
    incorrect information about the semantics of exit(). (I'm not
    claiming he did so deliberately, and it's not relevant that Mabden was
    the one who did it.) Several of us then posted followups correcting
    his error. Now you're pretending to have a problem with those of us
    who posted correct information.

    I don't believe you.

    I know you think this kind of thing is fun. In the past, you have
    deliberately forged a quotation from another poster, and when called
    on it, you wrote "We do it because it is fun!". See

    I don't seriously expect you to change your behavior; I post this
    mostly as a warning to others and as a recommendation for their
    Keith Thompson, Oct 28, 2005
  19. Yes, and returning arbitrarily chosen values can lead to unexpectedly
    excited users, as for instance VMS interprets many of them as message
    IDs, and prints the attached system warning message:

    VMS-I-DISMOUNT the tape in DRA4: has been dismounted
    VMS-I-SHUTDOWN cluster shutdown in progress at your request
    VMS-I-OVERTEMP the CPU core has reached critical temperature
    Mark McIntyre, Oct 28, 2005
  20. On Fri, 28 Oct 2005 16:36:06 GMT, in comp.lang.c ,
    talking to yourself is a bad sign...
    Just because you're a dipstick doesn't mean we all have to ignore
    obvious mistakes in posts.
    Its large, pink and not really there. Reminds me of something...
    Mark McIntyre, Oct 28, 2005
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.