liveBook · Manning

Abort

As explained in Modern C

abort is the C standard library function that causes abnormal program termination and may suppress some system cleanup processing.

Registering an exit handler does not guarantee that it will run: atexit(sayGoodBye); ... abort(); abort terminates the program abnormally, bypassing application-specific atexit handlers and some system cleanup. TAKEAWAY: use it with extreme care. section 8.7

The termination functions differ in how much cleanup they preserve:

  • quick_exit runs handlers registered with at_quick_exit. section 8.7
  • _Exit suppresses application-specific handlers but permits platform-specific cleanup such as file closure. section 8.7
  • abort is more intrusive because it also inhibits some system cleanup. section 8.7

Runtime assertion failure

When assert detects a condition that should always hold, it prints a diagnostic and calls abort. A failure can expose a false assumption during debugging, but such assertions and messages should not remain in a production executable. section 8.7

How Modern C covers it

How deep it goes
Defines abort's cleanup behavior and contrasts it with quick_exit and _Exit, without detailing platform-specific cleanup rules.
Examples
Uses an atexit handler, a failed runtime assertion, and its diagnostic output.
What you can do after
Diagnose/debug false runtime assumptions with assertions while recognizing abort's harmful production consequences.
How it connects
Connects abort with atexit, quick_exit, _Exit, assert, and NDEBUG.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C. The section links point to the parts of the book it draws on.