autoconf: Exiting Portably
1
1 13.8 Exiting Portably
1 =====================
1
1 A C or C++ program can exit with status N by returning N from the
1 `main' function. Portable programs are supposed to exit either with
1 status 0 or `EXIT_SUCCESS' to succeed, or with status `EXIT_FAILURE' to
1 fail, but in practice it is portable to fail by exiting with status 1,
1 and test programs that assume Posix can fail by exiting with status
1 values from 1 through 255. Programs on SunOS 2.0 (1985) through 3.5.2
1 (1988) incorrectly exited with zero status when `main' returned
1 nonzero, but ancient systems like these are no longer of practical
1 concern.
1
1 A program can also exit with status N by passing N to the `exit'
1 function, and a program can fail by calling the `abort' function. If a
1 program is specialized to just some platforms, it can fail by calling
1 functions specific to those platforms, e.g., `_exit' (Posix) and
1 `_Exit' (C99). However, like other functions, an exit function should
1 be declared, typically by including a header. For example, if a C
1 program calls `exit', it should include `stdlib.h' either directly or
1 via the default includes (⇒Default Includes).
1
1 A program can fail due to undefined behavior such as dereferencing a
1 null pointer, but this is not recommended as undefined behavior allows
1 an implementation to do whatever it pleases and this includes exiting
1 successfully.
1