Versions Compared

Key

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

...

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

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

Calling exit()

  • Flushes unwritten buffered data.
  • Closes all open files.
  • Removes temporary files.
  • Returns an integer exit status to the operating system.

...

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

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

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

...

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

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

The abort() function causes abnormal program termination to occur, unless the signal SIGABRT is being caught and the signal handler does not return.

...

For example, calling:

Code Block
bgColor#ccccff
  atexit(turn_gizmo_off); 

"registers" the turn_gizmo_off() function so that a subsequent call to exit() will invoke turn_gizmo_off(); as it terminates the program. The C standard says that atexit() should let you register up to 32 functions.

...

ERR03-A. Use runtime-constraint handlers when calling functions defined by TR24731-1      1312. Error Handling (ERR)       ERR05-A. Application-independent code must provide error detection without dictating error handling