Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This is the standard C function to end a program. It takes one argument, which should be either EXIT_SUCCESS or EXIT_FAILURE indicating normal or abnormal termination. It never returns.

Code Block
bgColor#ccccff
#include <stdlib.h>
/* ... */

if (/* something really bad happened */) {
  exit(EXIT_FAILURE); 
}

...

A less polite function, _exit() also takes one argument and never returns. The standard specifies that _exit() also closes open file descriptors, but does not specify if _exit() flushes file buffers or deletes temporary files.

The _Exit() function is a synonym for _exit()

code
Code Block
bgColor#ccccff
#include <stdlib.h>
/* ... */

if (/* something really bad happened */) {
  _exit(EXIT_FAILURE); 
}

The _Exit() function is a synonym for _exit()

abort()

The quickest way to terminate a program, abort() takes no parameter, and always signifies abnormal termination to the operating system.

Code Block
bgColor#ccccff
#include <stdlib.h>
/* ... */

if (/* something really bad happened */) {
  abort(); 
}

...