xref: /netbsd-src/external/gpl3/gcc.old/dist/libstdc++-v3/doc/html/manual/termination.html (revision b7b7574d3bf8eeb51a1fa3977b59142ec6434a55)
1<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Chapter 6. Termination</title><meta name="generator" content="DocBook XSL Stylesheets V1.75.2" /><meta name="keywords" content="&#10;      ISO C++&#10;    , &#10;      library&#10;    " /><link rel="home" href="../spine.html" title="The GNU C++ Library Documentation" /><link rel="up" href="support.html" title="Part II.  Support" /><link rel="prev" href="dynamic_memory.html" title="Chapter 5. Dynamic Memory" /><link rel="next" href="verbose_termination.html" title="Verbose Terminate Handler" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 6. Termination</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="dynamic_memory.html">Prev</a> </td><th width="60%" align="center">Part II. 
4  Support
5
6</th><td width="20%" align="right"> <a accesskey="n" href="verbose_termination.html">Next</a></td></tr></table><hr /></div><div class="chapter" title="Chapter 6. Termination"><div class="titlepage"><div><div><h2 class="title"><a id="manual.support.termination"></a>Chapter 6. Termination</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="termination.html#support.termination.handlers">Termination Handlers</a></span></dt><dt><span class="sect1"><a href="verbose_termination.html">Verbose Terminate Handler</a></span></dt></dl></div><div class="sect1" title="Termination Handlers"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="support.termination.handlers"></a>Termination Handlers</h2></div></div></div><p>
7      Not many changes here to <code class="filename">cstdlib</code>.  You should note that the
8      <code class="function">abort()</code> function does not call the
9      destructors of automatic nor static objects, so if you're
10      depending on those to do cleanup, it isn't going to happen.
11      (The functions registered with <code class="function">atexit()</code>
12      don't get called either, so you can forget about that
13      possibility, too.)
14    </p><p>
15      The good old <code class="function">exit()</code> function can be a bit
16      funky, too, until you look closer.  Basically, three points to
17      remember are:
18    </p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem"><p>
19	Static objects are destroyed in reverse order of their creation.
20	</p></li><li class="listitem"><p>
21	Functions registered with <code class="function">atexit()</code> are called in
22        reverse order of registration, once per registration call.
23        (This isn't actually new.)
24	</p></li><li class="listitem"><p>
25	The previous two actions are <span class="quote">“<span class="quote">interleaved,</span>”</span> that is,
26        given this pseudocode:
27	</p><pre class="programlisting">
28  extern "C or C++" void  f1 (void);
29  extern "C or C++" void  f2 (void);
30
31  static Thing obj1;
32  atexit(f1);
33  static Thing obj2;
34  atexit(f2);
35</pre><p>
36        then at a call of <code class="function">exit()</code>,
37        <code class="varname">f2</code> will be called, then
38        <code class="varname">obj2</code> will be destroyed, then
39        <code class="varname">f1</code> will be called, and finally
40        <code class="varname">obj1</code> will be destroyed. If
41        <code class="varname">f1</code> or <code class="varname">f2</code> allow an
42        exception to propagate out of them, Bad Things happen.
43	</p></li></ol></div><p>
44      Note also that <code class="function">atexit()</code> is only required to store 32
45      functions, and the compiler/library might already be using some of
46      those slots.  If you think you may run out, we recommend using
47      the <code class="function">xatexit</code>/<code class="function">xexit</code> combination from <code class="literal">libiberty</code>, which has no such limit.
48    </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="dynamic_memory.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="support.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="verbose_termination.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 5. Dynamic Memory </td><td width="20%" align="center"><a accesskey="h" href="../spine.html">Home</a></td><td width="40%" align="right" valign="top"> Verbose Terminate Handler</td></tr></table></div></body></html>
49