Standard return defs?

S

Stephen Mayes

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
 
P

pete

Stephen said:
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.
 
E

Emmanuel Delahaye

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

Keith Thompson

Stephen Mayes said:
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.
 
J

Joona I Palaste

Stephen Mayes said:
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.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top