Standard return defs?

Discussion in 'C Programming' started by Stephen Mayes, Aug 11, 2004.

  1. I notice in my stdlib.h:

    #define EXIT_FAILURE 1 /* Failing exit status. */
    #define EXIT_SUCCESS 0 /* Successful exit status. */

    Are these definitions dictated by the standard? I've seen them used often
    in
    this group so I assume they are.

    If so, are there any other standard defined return values that I could use
    in functions?
    i.e RETURN_SUCCESS, ERR_NO_MEM, ERR_FILE_NOT_OPENED, ERR_BAD_PROGRAMMER, or
    such?

    Stephen
     
    Stephen Mayes, Aug 11, 2004
    #1
    1. Advertising

  2. Stephen Mayes

    pete Guest

    Stephen Mayes wrote:
    >
    > I notice in my stdlib.h:
    >
    > #define EXIT_FAILURE 1 /* Failing exit status. */
    > #define EXIT_SUCCESS 0 /* Successful exit status. */
    >
    > Are these definitions dictated by the standard?


    Yes. The values are implementation defined.

    > I've seen them used often in this group so I assume they are.
    >
    > If so, are there any other standard defined return values
    > that I could use in functions?


    No.

    --
    pete
     
    pete, Aug 12, 2004
    #2
    1. Advertising

  3. Stephen Mayes wrote on 12/08/04 :
    > I notice in my stdlib.h:
    >
    > #define EXIT_FAILURE 1 /* Failing exit status. */
    > #define EXIT_SUCCESS 0 /* Successful exit status. */
    >
    > Are these definitions dictated by the standard? I've seen them used often
    > in
    > this group so I assume they are.


    Yes. There are used with exit() and the return from main().

    > If so, are there any other standard defined return values that I could use
    > in functions?


    Not that I am aware of. Of course you have the errno values (Exxx) .

    --
    Emmanuel
    The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html

    "C is a sharp tool"
     
    Emmanuel Delahaye, Aug 12, 2004
    #3
  4. "Stephen Mayes" <> writes:
    > I notice in my stdlib.h:
    >
    > #define EXIT_FAILURE 1 /* Failing exit status. */
    > #define EXIT_SUCCESS 0 /* Successful exit status. */
    >
    > Are these definitions dictated by the standard? I've seen them used
    > often in this group so I assume they are.


    As pete pointed out, EXIT_FAILURE and EXIT_SUCCESS are standard, but
    their values are implementation-defined. The value 0 also denotes a
    successful exit status; it may or may not be equal to EXIT_SUCCESS.

    > If so, are there any other standard defined return values that I
    > could use in functions? i.e RETURN_SUCCESS, ERR_NO_MEM,
    > ERR_FILE_NOT_OPENED, ERR_BAD_PROGRAMMER, or such?


    EXIT_SUCCESS and EXIT_FAILURE are intended to be passed to the exit()
    function or (nearly equivalently) used as the return value from
    main(). They're not intended to be returned from arbitrary functions.
    You can certainly use them that way if you want to, but it's likely to
    cause confusion.

    --
    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, Aug 12, 2004
    #4
  5. Stephen Mayes <> scribbled the following:
    > I notice in my stdlib.h:


    > #define EXIT_FAILURE 1 /* Failing exit status. */
    > #define EXIT_SUCCESS 0 /* Successful exit status. */


    > Are these definitions dictated by the standard? I've seen them used often
    > in
    > this group so I assume they are.


    These macros are standard but their expansions aren't. You can't depend
    on EXIT_SUCCESS being 0, and you certainly can't depend on EXIT_FAILURE
    being 1. However, 0 will always work as a return value meaning
    successful exit.

    > If so, are there any other standard defined return values that I could use
    > in functions?
    > i.e RETURN_SUCCESS, ERR_NO_MEM, ERR_FILE_NOT_OPENED, ERR_BAD_PROGRAMMER, or
    > such?


    Not that I know of.

    --
    /-- Joona Palaste () ------------- Finland --------\
    \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
    "To know me IS to love me."
    - JIPsoft
     
    Joona I Palaste, Aug 12, 2004
    #5
    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. nooobody
    Replies:
    0
    Views:
    524
    nooobody
    Nov 30, 2004
  2. Replies:
    8
    Views:
    297
  3. bruce
    Replies:
    3
    Views:
    363
  4. G Patel

    .defs & .s file extension

    G Patel, Mar 7, 2005, in forum: C Programming
    Replies:
    2
    Views:
    526
    James McIninch
    Mar 8, 2005
  5. Replies:
    5
    Views:
    345
Loading...

Share This Page