Name | Description | Notes | Source | Availability | |||||||
---|---|---|---|---|---|---|---|---|---|---|---|
_Exit() |
Terminate program without registered activity | (·) | <stdlib.h> |
C99 | C11 | ||||||
abort() |
Abort program execution | (·) | <stdlib.h> |
C89 | C90 | C95 | C99 | C11 | |||
at_ |
Register activity on quick termination | (·) | <stdlib.h> |
C11 | |||||||
atexit() |
Register activity on normal termination | (·) | <stdlib.h> |
C89 | C90 | C95 | C99 | C11 | |||
EXIT_ |
Indication of program failure | M | <stdlib.h> |
C89 | C90 | C95 | C99 | C11 | |||
EXIT_ |
Indication of program success | M | <stdlib.h> |
C89 | C90 | C95 | C99 | C11 | |||
exit() |
Terminate program | (·) | <stdlib.h> |
C89 | C90 | C95 | C99 | C11 | |||
main() |
Entry and exit point of program | (·) | User-defined | C89 | C90 | C95 | C99 | C11 | |||
quick_ |
Terminate program without signals | (·) | <stdlib.h> |
C11 | |||||||
SIGABRT |
Execution aborted | M | <signal.h> |
C89 | C90 | C95 | C99 | C11 |
In a hosted environment, a C program begins
with the invocation of a user-defined function called
main
, which must have one of the following
prototypes:
int main(void); int main(int argc, const char *const *argv);
A program may be executed with a list of textual
arguments. argc
indicates how many
arguments were provided for the current execution, and these
are passed as null-terminated strings argv[1]
,
argv[2]
, etc. argv[argc]
is always
NULL
. argv[0]
is a pointer to a null-terminated string
which is often the program name, or the name used to
determine that this program should be executed.
A C program can end under several conditions, and may terminate normally or abnormally. When it terminates normally, all open streams are properly flushed and closed, and all temporary files are deleted.
When a program terminates, it does so with an exit
status. The program terminates normally when the
initial invocation of
main
terminates, and the return value of that
invocation becomes the exit status. The exit status of a
program invoked with system
is returned by that function.
Programs should exit with status 0
or
EXIT_
to indicate that the program
was successful, or with
EXIT_
to indicate that it failed to
do what was intended. Other values may be returned to signify
other implementation-defined meanings.
EXIT_
and
EXIT_
are defined in <stdlib.h>
.
#include<stdlib.h>
_Noreturn void exit(int status); _Noreturn void _Exit(int status); _Noreturn void quick_exit (int status);
A program may exit prematurely, but normally, by calling
exit
,
quick_
or
_Exit
. The argument becomes the exit
status.
#include<stdlib.h>
void atexit(void (*func)(void)); void at_quick_ (void (*func)(void));exit
User-defined functions may be specified to be executed
during program termination. Two lists of functions are
defined, with
atexit
adding the function
pointer func
to one of them, and
at_
adding to the other.
Both functions add to the heads of their respective
lists.
If a program terminates with exit
,
or by returning from
main
, the functions in the list established by
atexit
are executed. Terminating with
quick_
first invokes the functions in
the list established by
at_
.
_Exit
invokes no functions from either
list.
#include <stdlib.h>
_Noreturn void abort(void);
abort
causes abnormal termination of the program by invoking
raise(SIGABRT)
.
The exit status is unspecified, except that it will be
distinct from 0
and
EXIT_
. assert
calls abort
when its assertion fails.