Aborts the current process and returns an error code.
void abort( void );
Routine | Required Header | Compatibility |
abort | <process.h> or <stdlib.h> | ANSI, Win 95, Win NT |
For additional compatibility information, see Compatibility in the Introduction.
Libraries
LIBC.LIB | Single thread static library, retail version |
LIBCMT.LIB | Multithread static library, retail version |
MSVCRT.LIB | Import library for MSVCRT.DLL, retail version |
Return Value
abort does not return control to the calling process. By default, it terminates the current process and returns an exit code of 3.
Remarks
The abort routine prints the message “abnormal program termination
” and then calls raise(SIGABRT). The action taken in response to the SIGABRT signal depends on what action has been defined for that signal in a prior call to the signal function. The default SIGABRT action is for the calling process to terminate with exit code 3, returning control to the calling process or operating system. abort does not flush stream buffers or do atexit/_onexit processing.
abort determines the destination of the message based on the type of application that called the routine. Console applications always receive the message via stderr. In a single or multithreaded Windows application, abort calls the Windows MessageBox API to create a message box to display the message along with an OK button. When the user selects OK, the program aborts immediately.
When the application is linked with a debug version of the run-time libraries, abort creates a message box with three buttons: Abort, Retry, and Ignore. If the user selects Abort, the program aborts immediately. If the user selects Retry, the debugger is called and the user can debug the program if Just-In-Time (JIT) debugging is enabled. If the user selects Ignore, abort continues with its normal execution: creating the message box with the OK button. For more information, see Using C Run-Time Library Debugging Support.
Example
/* ABORT.C: This program tries to open a
* file and aborts if the attempt fails.
*/
#include <stdio.h>
#include <stdlib.h>
void main( void )
{
FILE *stream;
if( (stream = fopen( "NOSUCHF.ILE", "r" )) == NULL )
{
perror( "Couldn't open file" );
abort();
}
else
fclose( stream );
}
Output
Couldn't open file: No such file or directory
abnormal program termination
Process and Environment Control Routines
See Also _exec Function Overview, exit, raise, signal, _spawn Function Overview, _DEBUG