home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!uunet.ca!wildcan!sq!msb
- From: msb@sq.sq.com (Mark Brader)
- Subject: Re: How to use 'return' in c?
- Message-ID: <1992Nov5.054934.29397@sq.sq.com>
- Organization: SoftQuad Inc., Toronto, Canada
- References: <1992Oct29.025437.9289@nuscc.nus.sg> <1992Nov2.203701.162@ipact.com> <1992Nov4.231347.26999@u.washington.edu>
- Date: Thu, 5 Nov 92 05:49:34 GMT
- Lines: 54
-
- > After several people wrote me on the use of EXIT_SUCCESS and
- > EXIT_FAILURE and their inability to locate those files on their
- > systems I checked K&R 2ndEd for the definitive answer...
- >
- > " void exit(int status)
- > ... How status is returned to the environment is
- > implementation-dependent, but zero is taken as successful
- > termination. The values EXIT_SUCCESS and EXIT_FAILURE may also
- > be used." ^^^
- >
- > Because the word *may* is used I must assume that you either get
- > it or you don't depending on your compiler/OS. ...
-
- No. What's going on here is that K&R2 is about ANSI C (a.k.a. ISO C,
- or standard C), but the standard is a relatively new thing (less than
- 3 years) and there are still lots of older compilers around.
-
- An ANSI C implementation *must* provide EXIT_SUCCESS and EXIT_FAILURE
- in the header <stdlib.h>, and you *may* use them to specify your status.
- Alternatively you may use 0, which is also specified as indicating
- success, or some other number, whose meaning will be specific to your
- implementation.
-
- Older implementations generally did *not* provide EXIT_SUCCESS, EXIT_-
- FAILURE, or for that matter, <stdlib.h>. On UNIX and I believe most
- other environments, 0 was specified as success and anything else
- indicated failure. However, not all environments conformed to this;
- on VMS, for instance, success and failure were indicated by *odd* and
- *even* status returns, with specific values encoding specific types
- of success or failure.
-
- For portability to ANSI C and to older systems using the UNIX convention,
- the following is one possibility:
-
- #if __STDC__
- #include <stdlib.h>
- #endif
-
- #ifndef EXIT_FAILURE
- #define EXIT_FAILURE 1
- #endif
-
- #ifndef EXIT_SUCCESS
- #define EXIT_SUCCESS 0
- #endif
-
- Then use EXIT_SUCCESS or EXIT_FAILURE.
- --
- Mark Brader "In the rough, roguish, early days, when men were
- SoftQuad Inc., Toronto men, women were women, and pointers were ints,
- utzoo!sq!msb Real C Programmers wouldn't even bother to invent
- msb@sq.com tags for structs ..." -- Steve Summit
-
- This article is in the public domain.
-