xref: /netbsd-src/external/gpl3/gcc/dist/libstdc++-v3/doc/html/manual/support.html (revision fb8a8121f28072308659629b86cfb7c449bd93e1)
14fee23f9Smrg<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2d79abf08Smrg<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Chapter 4.  Support</title><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><meta name="keywords" content="ISO C++, library" /><meta name="keywords" content="ISO C++, runtime, library" /><link rel="home" href="../index.html" title="The GNU C++ Library" /><link rel="up" href="std_contents.html" title="Part II.  Standard Contents" /><link rel="prev" href="std_contents.html" title="Part II.  Standard Contents" /><link rel="next" href="dynamic_memory.html" title="Dynamic Memory" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 4. 
34fee23f9Smrg  Support
44fee23f9Smrg
548fb7bfaSmrg</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="std_contents.html">Prev</a> </td><th width="60%" align="center">Part II. 
648fb7bfaSmrg    Standard Contents
748fb7bfaSmrg  </th><td width="20%" align="right"> <a accesskey="n" href="dynamic_memory.html">Next</a></td></tr></table><hr /></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a id="std.support"></a>Chapter 4. 
84fee23f9Smrg  Support
94d5abbe8Smrg  <a id="id-1.3.4.2.1.1.1" class="indexterm"></a>
10*fb8a8121Smrg</h2></div></div></div><div class="toc"><p><strong>Table of Contents</strong></p><dl class="toc"><dt><span class="section"><a href="support.html#std.support.types">Types</a></span></dt><dd><dl><dt><span class="section"><a href="support.html#std.support.types.fundamental">Fundamental Types</a></span></dt><dt><span class="section"><a href="support.html#std.support.types.numeric_limits">Numeric Properties</a></span></dt><dt><span class="section"><a href="support.html#std.support.types.null">NULL</a></span></dt></dl></dd><dt><span class="section"><a href="dynamic_memory.html">Dynamic Memory</a></span></dt><dd><dl><dt><span class="section"><a href="dynamic_memory.html#std.support.memory.notes">Additional Notes</a></span></dt></dl></dd><dt><span class="section"><a href="termination.html">Termination</a></span></dt><dd><dl><dt><span class="section"><a href="termination.html#support.termination.handlers">Termination Handlers</a></span></dt><dt><span class="section"><a href="termination.html#support.termination.verbose">Verbose Terminate Handler</a></span></dt></dl></dd></dl></div><p>
1148fb7bfaSmrg    This part deals with the functions called and objects created
1248fb7bfaSmrg    automatically during the course of a program's existence.
1348fb7bfaSmrg  </p><p>
1448fb7bfaSmrg    While we can't reproduce the contents of the Standard here (you
1548fb7bfaSmrg    need to get your own copy from your nation's member body; see our
1648fb7bfaSmrg    homepage for help), we can mention a couple of changes in what
1748fb7bfaSmrg    kind of support a C++ program gets from the Standard Library.
1848fb7bfaSmrg  </p><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="std.support.types"></a>Types</h2></div></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="std.support.types.fundamental"></a>Fundamental Types</h3></div></div></div><p>
1948fb7bfaSmrg      C++ has the following builtin types:
2048fb7bfaSmrg    </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
2148fb7bfaSmrg	char
2248fb7bfaSmrg      </p></li><li class="listitem"><p>
2348fb7bfaSmrg	signed char
2448fb7bfaSmrg      </p></li><li class="listitem"><p>
2548fb7bfaSmrg	unsigned char
2648fb7bfaSmrg      </p></li><li class="listitem"><p>
2748fb7bfaSmrg	signed short
2848fb7bfaSmrg      </p></li><li class="listitem"><p>
2948fb7bfaSmrg	signed int
3048fb7bfaSmrg      </p></li><li class="listitem"><p>
3148fb7bfaSmrg	signed long
3248fb7bfaSmrg      </p></li><li class="listitem"><p>
3348fb7bfaSmrg	unsigned short
3448fb7bfaSmrg      </p></li><li class="listitem"><p>
3548fb7bfaSmrg	unsigned int
3648fb7bfaSmrg      </p></li><li class="listitem"><p>
3748fb7bfaSmrg	unsigned long
3848fb7bfaSmrg      </p></li><li class="listitem"><p>
3948fb7bfaSmrg	bool
4048fb7bfaSmrg      </p></li><li class="listitem"><p>
4148fb7bfaSmrg	wchar_t
4248fb7bfaSmrg      </p></li><li class="listitem"><p>
4348fb7bfaSmrg	float
4448fb7bfaSmrg      </p></li><li class="listitem"><p>
4548fb7bfaSmrg	double
4648fb7bfaSmrg      </p></li><li class="listitem"><p>
4748fb7bfaSmrg	long double
4848fb7bfaSmrg      </p></li></ul></div><p>
4948fb7bfaSmrg      These fundamental types are always available, without having to
5048fb7bfaSmrg      include a header file. These types are exactly the same in
5148fb7bfaSmrg      either C++ or in C.
5248fb7bfaSmrg    </p><p>
5348fb7bfaSmrg      Specializing parts of the library on these types is prohibited:
5448fb7bfaSmrg      instead, use a POD.
5548fb7bfaSmrg    </p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="std.support.types.numeric_limits"></a>Numeric Properties</h3></div></div></div><p>
56*fb8a8121Smrg    The header <code class="filename">&lt;limits&gt;</code> defines
5748fb7bfaSmrg    traits classes to give access to various implementation
5848fb7bfaSmrg    defined-aspects of the fundamental types. The traits classes --
59181254a7Smrg    fourteen in total -- are all specializations of the class template
60181254a7Smrg    <code class="classname">numeric_limits</code>
6148fb7bfaSmrg    and defined as follows:
6248fb7bfaSmrg    </p><pre class="programlisting">
6348fb7bfaSmrg   template&lt;typename T&gt;
6448fb7bfaSmrg     struct class
6548fb7bfaSmrg     {
6648fb7bfaSmrg       static const bool is_specialized;
6748fb7bfaSmrg       static T max() throw();
6848fb7bfaSmrg       static T min() throw();
6948fb7bfaSmrg
7048fb7bfaSmrg       static const int digits;
7148fb7bfaSmrg       static const int digits10;
7248fb7bfaSmrg       static const bool is_signed;
7348fb7bfaSmrg       static const bool is_integer;
7448fb7bfaSmrg       static const bool is_exact;
7548fb7bfaSmrg       static const int radix;
7648fb7bfaSmrg       static T epsilon() throw();
7748fb7bfaSmrg       static T round_error() throw();
7848fb7bfaSmrg
7948fb7bfaSmrg       static const int min_exponent;
8048fb7bfaSmrg       static const int min_exponent10;
8148fb7bfaSmrg       static const int max_exponent;
8248fb7bfaSmrg       static const int max_exponent10;
8348fb7bfaSmrg
8448fb7bfaSmrg       static const bool has_infinity;
8548fb7bfaSmrg       static const bool has_quiet_NaN;
8648fb7bfaSmrg       static const bool has_signaling_NaN;
8748fb7bfaSmrg       static const float_denorm_style has_denorm;
8848fb7bfaSmrg       static const bool has_denorm_loss;
8948fb7bfaSmrg       static T infinity() throw();
9048fb7bfaSmrg       static T quiet_NaN() throw();
9148fb7bfaSmrg       static T denorm_min() throw();
9248fb7bfaSmrg
9348fb7bfaSmrg       static const bool is_iec559;
9448fb7bfaSmrg       static const bool is_bounded;
9548fb7bfaSmrg       static const bool is_modulo;
9648fb7bfaSmrg
9748fb7bfaSmrg       static const bool traps;
9848fb7bfaSmrg       static const bool tinyness_before;
9948fb7bfaSmrg       static const float_round_style round_style;
10048fb7bfaSmrg     };
10148fb7bfaSmrg   </pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="std.support.types.null"></a>NULL</h3></div></div></div><p>
10248fb7bfaSmrg     The only change that might affect people is the type of
10348fb7bfaSmrg     <code class="constant">NULL</code>: while it is required to be a macro,
10448fb7bfaSmrg     the definition of that macro is <span class="emphasis"><em>not</em></span> allowed
105*fb8a8121Smrg     to be an expression with pointer type such as
106*fb8a8121Smrg     <code class="constant">(void*)0</code>, which is often used in C.
10748fb7bfaSmrg    </p><p>
10848fb7bfaSmrg     For <span class="command"><strong>g++</strong></span>, <code class="constant">NULL</code> is
10948fb7bfaSmrg     <code class="code">#define</code>'d to be
11048fb7bfaSmrg     <code class="constant">__null</code>, a magic keyword extension of
111*fb8a8121Smrg     <span class="command"><strong>g++</strong></span> that is slightly safer than a plain integer.
11248fb7bfaSmrg    </p><p>
11348fb7bfaSmrg     The biggest problem of #defining <code class="constant">NULL</code> to be
11448fb7bfaSmrg     something like <span class="quote">“<span class="quote">0L</span>”</span> is that the compiler will view
11548fb7bfaSmrg     that as a long integer before it views it as a pointer, so
116*fb8a8121Smrg     overloading won't do what you expect. It might not even have the
117*fb8a8121Smrg     same size as a pointer, so passing <code class="constant">NULL</code> to a
118*fb8a8121Smrg     varargs function where a pointer is expected might not even work
119*fb8a8121Smrg     correctly if <code class="code">sizeof(NULL) &lt; sizeof(void*)</code>.
120*fb8a8121Smrg     The G++ <code class="constant">__null</code> extension is defined so that
121*fb8a8121Smrg     <code class="code">sizeof(__null) == sizeof(void*)</code> to avoid this problem.
122*fb8a8121Smrg    </p><p>
123*fb8a8121Smrg     Scott Meyers explains this in more detail in his book
124*fb8a8121Smrg     <a class="link" href="https://www.aristeia.com/books.html" target="_top"><span class="emphasis"><em>Effective
125*fb8a8121Smrg     Modern C++</em></span></a> and as a guideline to solve this problem
126*fb8a8121Smrg     recommends to not overload on pointer-vs-integer types to begin with.
127*fb8a8121Smrg    </p><p>
128*fb8a8121Smrg     The C++ 2011 standard added the <code class="constant">nullptr</code> keyword,
129*fb8a8121Smrg     which is a null pointer constant of a special type,
130*fb8a8121Smrg     <code class="classname">std::nullptr_t</code>. Values of this type can be
131*fb8a8121Smrg     implicitly converted to <span class="emphasis"><em>any</em></span> pointer type,
132*fb8a8121Smrg     and cannot convert to integer types or be deduced as an integer type.
133*fb8a8121Smrg     Unless you need to be compatible with C++98/C++03 or C you should prefer
134*fb8a8121Smrg     to use <code class="constant">nullptr</code>  instead of <code class="constant">NULL</code>.
13548fb7bfaSmrg    </p></div></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="std_contents.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="std_contents.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="dynamic_memory.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Part II. 
13648fb7bfaSmrg    Standard Contents
13748fb7bfaSmrg   </td><td width="20%" align="center"><a accesskey="h" href="../index.html">Home</a></td><td width="40%" align="right" valign="top"> Dynamic Memory</td></tr></table></div></body></html>