exit(), location unknown ...

This is a discussion on exit(), location unknown ... within the C Programming forums, part of the General Programming Boards category; so exit(); should return to the end of program. but what num shoud i return inside of the exit();???...

  1. #1
    ~- Y u n a -~ beely's Avatar
    Join Date
    Dec 2001
    Posts
    291

    exit(), location unknown ...

    so exit(); should return to the end of program.

    but what num shoud i return inside of the exit();???

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >but what num shoud i return inside of the exit();???
    You can return anything that the calling process accepts, but the three portable values are 0, EXIT_SUCCESS, and EXIT_FAILURE.

    -Prelude
    My best code is written with the delete key.

  3. #3
    ~- Y u n a -~ beely's Avatar
    Join Date
    Dec 2001
    Posts
    291
    but why did most of the reference books shown ..

    exit (100);
    and then at the end of the prog shown exit (100);

    so what's the meaning stand for? no meaning anyway ??

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Many people seem to think that you can return any value as long as it's a valid int, they're wrong.

    -Prelude
    My best code is written with the delete key.

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    29
    I have seen in several source code that when testing for an error exit(1) is used. Does this substitute for EXIT_FAILURE?

  6. #6
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Straight out of stdlib.h

    Code:
    #define EXIT_FAILURE 1
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  7. #7
    Registered User jawwadalam's Avatar
    Join Date
    May 2002
    Posts
    131

    Every other number is passed back to the environment 'as is', and how the environment treats that number is implementation specific.
    What i have guessed from it.. that numbers other then 0 passed back to the environment..used for error detection by the environment..??? .. what i have read in many books that exit(0) is simply for exit with success and exit(1) for error...
    Is this function have different meanings with same output for different O/S's ??????
    One day you will ask what more important to you..
    I will say my life..
    and You will leave me with even knowing
    that
    You are my Life (L)

  8. #8
    Registered User unixOZ's Avatar
    Join Date
    Feb 2002
    Posts
    91
    if something goes wrong: exit(EXIT_FAILURE) or exit(1), if there is no problem exit(EXIT_SUCCESS) or exit(0)

  9. #9
    FCF
    FCF is offline
    Registered User FCF's Avatar
    Join Date
    Dec 2001
    Posts
    40
    Wat is the meaning of 1 and 0? It's define by the programmer.
    So, if the programmer write #define SUCCESS 1, the 1 represents success, if u returns 0 (not 1) so in any way this is not considered success. My conclusion is: Just use the EXIT_SUCCESS and the EXIT_FAILURE. They really represents their meanings.
    Life is difficult...

  10. #10
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by FCF
    Wat is the meaning of 1 and 0? It's define by the programmer.
    So, if the programmer write #define SUCCESS 1, the 1 represents success, if u returns 0 (not 1) so in any way this is not considered success.
    This doesn't make any sense. Sure for your personal use you may consider whatever value you define as success, success, but the OS won't be seeing eye to eye with you.

    Just because you create some macro named "SUCCESS", this doesn't mean that the OS or anyone else reading your program will treat it as the same. What you define as success or failure is really irrelevant.

    Other than the assigned values, anything else is as it's already been described: unspecified. The OS can do whatever it feels like with it.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Odd memory leaks
    By VirtualAce in forum C++ Programming
    Replies: 11
    Last Post: 05-25-2006, 12:56 AM
  2. Dynamic array of pointers
    By csisz3r in forum C Programming
    Replies: 8
    Last Post: 09-25-2005, 02:06 PM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  4. UNICODE and GET_STATE
    By Registered in forum C++ Programming
    Replies: 1
    Last Post: 07-15-2002, 03:23 PM
  5. Im so lost at . .
    By hermit in forum C Programming
    Replies: 18
    Last Post: 05-15-2002, 01:26 AM

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