blob: 8755f11ccbf7771fee45d0e78753f45f0531fce9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
<h1 id="firstHeading" class="firstHeading">abort</h1> <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code><stdlib.h></code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl t-until-c11"> <td><pre data-language="c">void abort(void);</pre></td> <td class="t-dcl-nopad"> </td> <td><span class="t-mark-rev t-until-c11">(until C11)</span></td> </tr> <tr class="t-dcl t-since-c11 t-until-c23"> <td> <pre data-language="c">_Noreturn void abort(void);</pre>
</td> <td class="t-dcl-nopad"> </td> <td> <span class="t-mark-rev t-since-c11">(since C11)</span> <br><span class="t-mark-rev t-until-c23">(until C23)</span> </td> </tr> <tr class="t-dcl t-since-c23"> <td> <pre data-language="c">[[noreturn]] void abort(void);</pre>
</td> <td class="t-dcl-nopad"> </td> <td> <span class="t-mark-rev t-since-c23">(since C23)</span> </td> </tr> </table> <p>Causes abnormal program termination unless <code><a href="sig_types" title="c/program/SIG types">SIGABRT</a></code> is being caught by a signal handler passed to signal and the handler does not return.</p>
<p>Functions passed to <code><a href="atexit" title="c/program/atexit">atexit()</a></code> are not called. Whether open resources such as files are closed is implementation defined. An implementation defined status is returned to the host environment that indicates unsuccessful execution.</p>
<h3 id="Parameters"> Parameters</h3> <p>(none)</p>
<h3 id="Return_value"> Return value</h3> <p>(none)</p>
<h3 id="Notes"> Notes</h3> <p>POSIX <a rel="nofollow" class="external text" href="https://pubs.opengroup.org/onlinepubs/9699919799/functions/abort.html">specifies</a> that the <code>abort()</code> function overrides blocking or ignoring the <code>SIGABRT</code> signal.</p>
<p>Some compiler intrinsics, e.g. <a rel="nofollow" class="external text" href="https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html"><code>__builtin_trap</code></a> (gcc, clang, and icc) or <a rel="nofollow" class="external text" href="https://learn.microsoft.com/en-us/cpp/intrinsics/fastfail"><code>__fastfail</code></a>/<a rel="nofollow" class="external text" href="https://learn.microsoft.com/en-us/cpp/intrinsics/debugbreak"><code>__debugbreak</code></a> (msvc), can be used to terminate the program as fast as possible.</p>
<h3 id="Example"> Example</h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#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;
}</pre></div> <p>Output:</p>
<div class="text source-text"><pre data-language="c">error opening file data.txt in function main()</pre></div> </div> <h3 id="References"> References</h3> <ul>
<li> C17 standard (ISO/IEC 9899:2018): </li>
<ul><li> 7.22.4.1 The abort function (p: 255) </li></ul>
<li> C11 standard (ISO/IEC 9899:2011): </li>
<ul><li> 7.22.4.1 The abort function (p: 350) </li></ul>
<li> C99 standard (ISO/IEC 9899:1999): </li>
<ul><li> 7.20.4.1 The abort function (p: 315) </li></ul>
<li> C89/C90 standard (ISO/IEC 9899:1990): </li>
<ul><li> 4.10.4.1 The abort function </li></ul>
</ul> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="exit" title="c/program/exit"> <span class="t-lines"><span>exit</span></span></a></div> </td> <td> causes normal program termination with cleaning up <br> <span class="t-mark">(function)</span> </td>
</tr> <tr class="t-dsc"> <td> <div><a href="atexit" title="c/program/atexit"> <span class="t-lines"><span>atexit</span></span></a></div> </td> <td> registers a function to be called on <code><a href="exit" title="c/program/exit">exit()</a></code> invocation <br> <span class="t-mark">(function)</span> </td>
</tr> <tr class="t-dsc"> <td> <div><a href="quick_exit" title="c/program/quick exit"> <span class="t-lines"><span>quick_exit</span></span></a></div>
<div><span class="t-lines"><span><span class="t-mark-rev t-since-c11">(C11)</span></span></span></div> </td> <td> causes normal program termination without completely cleaning up <br> <span class="t-mark">(function)</span> </td>
</tr> <tr class="t-dsc"> <td colspan="2"> <span><a href="https://en.cppreference.com/w/cpp/utility/program/abort" title="cpp/utility/program/abort">C++ documentation</a></span> for <code>abort</code> </td>
</tr> </table> <div class="_attribution">
<p class="_attribution-p">
© cppreference.com<br>Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.<br>
<a href="https://en.cppreference.com/w/c/program/abort" class="_attribution-link">https://en.cppreference.com/w/c/program/abort</a>
</p>
</div>
|