W3cubDocs

/C

abort

Defined in header <stdlib.h>
void abort(void);
(until C11)
_Noreturn void abort(void);
(since C11)

Causes abnormal program termination unless SIGABRT is being caught by a signal handler passed to signal and the handler does not return.

Functions passed to atexit() are not called. Whether open resources such as files are closed is implementation defined. Implementation defined status is returned to the host environment that indicates unsuccessful execution.

Parameters

(none).

Return value

(none).

Example

#include <stdio.h>
#include <stdlib.h>
 
int main(void) 
{
    FILE *fp = fopen("data.txt","r");
    if (fp == NULL) {
       fprintf(stderr, "error opening file data.txt in function main()\n");
       abort();
    }
 
    /* Normal processing continues here. */
    fclose(fp);
    printf("Normal Return\n");
    return 0;
}

Output:

error opening file data.txt in function main()

References

  • C11 standard (ISO/IEC 9899:2011):
    • 7.22.4.1 The abort function (p: 350)
  • C99 standard (ISO/IEC 9899:1999):
    • 7.20.4.1 The abort function (p: 315)
  • C89/C90 standard (ISO/IEC 9899:1990):
    • 4.10.4.1 The abort function

See also

causes normal program termination with cleaning up
(function)
registers a function to be called on exit() invocation
(function)
(C11)
causes normal program termination without completely cleaning up
(function)
C++ documentation for abort

© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/c/program/abort