Re: Conformance to standards, using exit() or return from main() correctly

From: George Greer (
Date: 01/07/01

On Sun, 7 Jan 2001, Peter Ajamian wrote:

>[...] Anyways, my understanding of the standard is that main can only
>return one of three values, those being 0 (to indicate success),
>EXIT_SUCCESS (which is #defined to 0 in stdlib.h), or EXIT_FAILURE (which
>is #defined to some non-zero value in stdlib.h).  An implementation can
>make use of other return values but does not have to and any other return
>values do not necessarily indicate success or failure. [...]
>Now after noticing a few instances where exit(1) is apparently used (in
>all likelihood incorrectly) to indicate failure I did the following from
>the shell...

In most programs:
!0 is failure
 0 is success

Programs can define exit(243) to be a partial success if they like, but you
have to change the 'if' statement in the shell to adapt.  Even DOS
considered IF ERRORLEVEL 1 (well, everything >1) lumped together.  The Unix
system has the shell's 'if' check testing for 0 as success and !0 as fail.
Anybody different?

You'll notice a 'exit(0)' in comm.c main() because it's a success.

Everything should be correct (I didn't investigate every case) and all
we'd gain is some #define instead of 1.

I think that was a "because we're not comfortable with numbers" #define on
the standards part.  Consider the NULL pointer, defined to be 0.  It gets
translated to whatever the hardware considers truly NULL so why not return
values too?  (Besides, we obey the standard by your definition.  We're not
returning EXIT_FAILURE, but we define 1 to be a failure so it fits.)

If you think standards are always right, look at socklen_t. :)

George Greer            | If it's about the CircleMUD mailing list,   | mail instead.

   | FAQ: |
   | Archives: |

This archive was generated by hypermail 2b30 : 12/03/01 PST