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?

    thanks!
    nick, Oct 13, 2005
    #1
    1. Advertising

  2. Charles M. Reinke, Oct 13, 2005
    #2
    1. Advertising

  3. nick <> wrote in news:dikavb$2a8r$1
    @justice.itsc.cuhk.edu.hk:

    > such as exit(0),exit(1)
    >
    > can i put any no. in the bracket?


    Yes, you can.

    > what is their meanings?


    Standard C defines only three valid values:

    0 and EXIT_SUCCESS

    mean that the program completed successfully.

    EXIT_FAILURE

    indicates a failure.

    The EXIT_* macros are defined in stdlib.h.

    For more information, see

    http://www.dinkumware.com/htm_cl/stdlib.html#exit

    Sinan

    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)
    A. Sinan Unur, Oct 13, 2005
    #3
  4. "Charles M. Reinke" <> wrote in news:dikbko$gk3$1
    @news-int.gatech.edu:

    > "nick" <> wrote in message
    > news:dikavb$2a8r$...
    >> such as exit(0),exit(1)
    >>
    >> can i put any no. in the bracket?
    >> what is their meanings?
    >>
    >> thanks!

    >
    > This should answer most of your questions:
    > http://ccs.ucsd.edu/c/stdlib.html#exit.


    Hmmm ... that seems to be a copy of the Dimkumware library documentation.
    I don't think they are allowed to put that on a publicly available web
    server:

    http://www.dinkumware.com/refxc.html

    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)
    A. Sinan Unur, Oct 13, 2005
    #4
  5. "A. Sinan Unur" <> wrote in message
    news:Xns96EDD8CCFF428asu1cornelledu@127.0.0.1...
    > "Charles M. Reinke" <> wrote in news:dikbko$gk3$1
    > @news-int.gatech.edu:
    >
    > > "nick" <> wrote in message
    > > news:dikavb$2a8r$...
    > >> such as exit(0),exit(1)
    > >>
    > >> can i put any no. in the bracket?
    > >> what is their meanings?
    > >>
    > >> thanks!

    > >
    > > This should answer most of your questions:
    > > http://ccs.ucsd.edu/c/stdlib.html#exit.

    >
    > Hmmm ... that seems to be a copy of the Dimkumware library documentation.
    > I don't think they are allowed to put that on a publicly available web
    > server:
    >
    > http://www.dinkumware.com/refxc.html
    >
    > --
    > A. Sinan Unur <>
    > (reverse each component and remove .invalid for email address)


    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
    Charles M. Reinke, Oct 13, 2005
    #5
  6. nick

    SM Ryan Guest

    nick <> wrote:
    # 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 http://www.rawbw.com/~wyrmwif/
    Elvis was an artist. But that didn't stop him from joining the service
    in time of war. That's why he is the king, and you're a shmuck.
    SM Ryan, Oct 13, 2005
    #6
  7. nick

    Mabden Guest

    "nick" <> wrote in message
    news:dikavb$2a8r$...
    > such as exit(0),exit(1)
    >
    > can i put any no. in the bracket?


    Yes.

    > what is their meanings?


    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
    Mabden, Oct 28, 2005
    #7
  8. "Mabden" <mabden@sbc_global.net> writes:
    > "nick" <> wrote in message
    > news:dikavb$2a8r$...
    >> such as exit(0),exit(1)
    >>
    >> can i put any no. in the bracket?

    >
    > Yes.
    >
    >> what is their meanings?

    >
    > Whatever you want. Zero means success. Anything else is considered an
    > error. You get to make up the error codes. It's YOUR program.


    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 (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, Oct 28, 2005
    #8
  9. Mabden wrote:
    > "nick" <> wrote in message
    > news:dikavb$2a8r$...


    >>such as exit(0),exit(1)
    >>can i put any no. in the bracket?


    > Yes.


    With a caveat.

    >>what is their meanings?


    > Whatever you want. Zero means success. Anything else is considered an
    > error. You get to make up the error codes. It's YOUR program.


    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
    termination'.
    Any other value has no standardly defined meaning but is
    implementation-defined. That implementation-definded meaning need not be
    failure.

    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
    #9
  10. nick

    Jordan Abel Guest

    On 2005-10-28, Mabden <mabden@sbc_global.net> wrote:
    > "nick" <> wrote in message
    > news:dikavb$2a8r$...
    >> such as exit(0),exit(1)
    >>
    >> can i put any no. in the bracket?

    >
    > Yes.
    >
    >> what is their meanings?

    >
    > Whatever you want. Zero means success. Anything else is considered
    > an error. You get to make up the error codes. It's YOUR program.


    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
    #10
  11. In article <e_j8f.1069$>,
    Martin Ambuhl <> wrote:
    ....
    >Please don't lie to the newbies. And if you don't know the answer, just
    >resist your irresistible urge to type bullshit.


    Calm down. Bad week to stop your meds.
    Kenny McCormack, Oct 28, 2005
    #11
  12. In article <LCj8f.6558$>,
    Mabden <mabden@sbc_global.net> wrote:
    >"nick" <> wrote in message
    >news:dikavb$2a8r$...
    >> such as exit(0),exit(1)
    >>
    >> can i put any no. in the bracket?

    >
    >Yes.
    >
    >> what is their meanings?

    >
    >Whatever you want. Zero means success. Anything else is considered an
    >error. You get to make up the error codes. It's YOUR program.


    So, you'd think. But you are about to be surprised by the thread-hijackers
    of this group...
    Kenny McCormack, Oct 28, 2005
    #12
  13. nick

    Jordan Abel Guest

    On 2005-10-28, Kenny McCormack <> wrote:
    > In article <LCj8f.6558$>,
    > Mabden <mabden@sbc_global.net> wrote:
    >>"nick" <> wrote in message
    >>news:dikavb$2a8r$...
    >>> such as exit(0),exit(1)
    >>>
    >>> can i put any no. in the bracket?

    >>
    >>Yes.
    >>
    >>> what is their meanings?

    >>
    >>Whatever you want. Zero means success. Anything else is considered
    >>an error. You get to make up the error codes. It's YOUR program.

    >
    > So, you'd think. But you are about to be surprised by the
    > thread-hijackers of this group...


    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
    #13
  14. In article <>,
    Jordan Abel <> wrote:
    >On 2005-10-28, Kenny McCormack <> wrote:
    >> In article <LCj8f.6558$>,
    >> Mabden <mabden@sbc_global.net> wrote:
    >>>"nick" <> wrote in message
    >>>news:dikavb$2a8r$...
    >>>> such as exit(0),exit(1)
    >>>>
    >>>> can i put any no. in the bracket?
    >>>
    >>>Yes.
    >>>
    >>>> what is their meanings?
    >>>
    >>>Whatever you want. Zero means success. Anything else is considered
    >>>an error. You get to make up the error codes. It's YOUR program.

    >>
    >> So, you'd think. But you are about to be surprised by the
    >> thread-hijackers of this group...

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


    (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
    #14
  15. Kenny McCormack wrote:
    > In article <e_j8f.1069$>,
    > Martin Ambuhl <> wrote:
    > ...
    >
    >>Please don't lie to the newbies. And if you don't know the answer, just
    >>resist your irresistible urge to type bullshit.

    >
    >
    > Calm down. Bad week to stop your meds.


    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
    #15
  16. Kenny McCormack wrote:
    > In article <>,
    > Jordan Abel <> wrote:
    > >On 2005-10-28, Kenny McCormack <> wrote:
    > >> In article <LCj8f.6558$>,
    > >> Mabden <mabden@sbc_global.net> wrote:
    > >>>"nick" <> wrote in message
    > >>>news:dikavb$2a8r$...
    > >>>> such as exit(0),exit(1)
    > >>>>
    > >>>> can i put any no. in the bracket?
    > >>>
    > >>>Yes.
    > >>>
    > >>>> what is their meanings?
    > >>>
    > >>>Whatever you want. Zero means success. Anything else is considered
    > >>>an error. You get to make up the error codes. It's YOUR program.
    > >>
    > >> So, you'd think. But you are about to be surprised by the
    > >> thread-hijackers of this group...

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

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


    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
    else's
    problem it is yours.

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

    Jordan Abel Guest

    On 2005-10-28, Kenny McCormack <> wrote:
    > In article <>,
    > Jordan Abel <> wrote:
    >>On 2005-10-28, Kenny McCormack <> wrote:
    >>> In article <LCj8f.6558$>,
    >>> Mabden <mabden@sbc_global.net> wrote:
    >>>>"nick" <> wrote in message
    >>>>news:dikavb$2a8r$...
    >>>>> such as exit(0),exit(1)
    >>>>>
    >>>>> can i put any no. in the bracket?
    >>>>
    >>>>Yes.
    >>>>
    >>>>> what is their meanings?
    >>>>
    >>>>Whatever you want. Zero means success. Anything else is considered
    >>>>an error. You get to make up the error codes. It's YOUR program.
    >>>
    >>> So, you'd think. But you are about to be surprised by the
    >>> thread-hijackers of this group...

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

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


    exit(256);

    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
    #17
  18. (Kenny McCormack) writes:
    > In article <>,
    > Jordan Abel <> wrote:
    >>On 2005-10-28, Kenny McCormack <> wrote:
    >>> In article <LCj8f.6558$>,
    >>> Mabden <mabden@sbc_global.net> wrote:
    >>>>"nick" <> wrote in message
    >>>>news:dikavb$2a8r$...
    >>>>> such as exit(0),exit(1)
    >>>>>
    >>>>> can i put any no. in the bracket?
    >>>>
    >>>>Yes.
    >>>>
    >>>>> what is their meanings?
    >>>>
    >>>>Whatever you want. Zero means success. Anything else is considered
    >>>>an error. You get to make up the error codes. It's YOUR program.
    >>>
    >>> So, you'd think. But you are about to be surprised by the
    >>> thread-hijackers of this group...

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

    >
    > (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, 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
    <http://groups.google.com/group/comp.lang.c/msg/cbd3d80fa3c64cb2>.

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

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, Oct 28, 2005
    #18
  19. On Fri, 28 Oct 2005 06:48:30 GMT, in comp.lang.c , Keith Thompson
    <> wrote:

    >"Mabden" <mabden@sbc_global.net> writes:
    >> "nick" <> wrote in message
    >> news:dikavb$2a8r$...
    >>> such as exit(0),exit(1)
    >>>
    >>> can i put any no. in the bracket?

    >>
    >> Yes.
    >>
    >>> what is their meanings?

    >>
    >> Whatever you want. Zero means success. Anything else is considered an
    >> error. You get to make up the error codes. It's YOUR program.

    >
    >That's incorrect. Either 0 or EXIT_SUCCESS means success.
    >EXIT_FAILURE means failure. Anything else is system-specific.


    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
    CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
    CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

    ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
    Mark McIntyre, Oct 28, 2005
    #19
  20. On Fri, 28 Oct 2005 16:36:06 GMT, in comp.lang.c ,
    (Kenny McCormack) wrote:

    >(To no one in particular)


    talking to yourself is a bad sign...
    >
    >See what I mean?


    Just because you're a dipstick doesn't mean we all have to ignore
    obvious mistakes in posts.

    >(I think you guys need to look up the phrase "SEP" - I believe it is
    >a Douglas Adams thing)


    Its large, pink and not really there. Reminds me of something...
    --
    Mark McIntyre
    CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
    CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

    ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
    Mark McIntyre, Oct 28, 2005
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?U2FuZHk=?=

    Code to Exit Web App and Exit Internet Explorer

    =?Utf-8?B?U2FuZHk=?=, Aug 3, 2005, in forum: ASP .Net
    Replies:
    7
    Views:
    7,873
    =?Utf-8?B?U2FuZHk=?=
    Aug 5, 2005
  2. Joe Smith
    Replies:
    4
    Views:
    65,786
    sandeep1976
    Nov 8, 2006
  3. Replies:
    2
    Views:
    441
    Jeff Epler
    May 31, 2005
  4. QQ
    Replies:
    5
    Views:
    505
    Jonathan Adams
    May 10, 2005
  5. Replies:
    4
    Views:
    734
Loading...

Share This Page