Name

abort

Synopsis

Ends program execution immediately

#include <stdlib.h>
voidabort( void );

The abort() function terminates execution of a program by raising the SIGABRT signal.

For a “clean” program termination, use the exit() function. abort() does not flush the buffers of open files or call any cleanup functions that you have installed using atexit(). The abort() function generally prints a message such as:

Abnormal program termination

on the stderr stream. In Unix, aborting a program also produces a core dump.

Example

struct record { long id;
                int data[256];
                struct record *next;
              };
/* ... */
struct record *new = (struct record *)malloc( sizeof(struct record) );
if ( new == NULL )            // Check whether malloc failed!
{
  fprintf( stderr, "%s: out of memory!", _  _func_  _ );abort();
}
else /* ... */

Get C in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.