xref: /netbsd-src/external/gpl3/gcc.old/dist/libstdc++-v3/doc/html/manual/support.html (revision 8feb0f0b7eaff0608f8350bbfa3098827b4bb91b)
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"><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. 
3  Support
4
5</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. 
6    Standard Contents
7  </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. 
8  Support
9  <a id="id-1.3.4.2.1.1.1" class="indexterm"></a>
10</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>
11    This part deals with the functions called and objects created
12    automatically during the course of a program's existence.
13  </p><p>
14    While we can't reproduce the contents of the Standard here (you
15    need to get your own copy from your nation's member body; see our
16    homepage for help), we can mention a couple of changes in what
17    kind of support a C++ program gets from the Standard Library.
18  </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>
19      C++ has the following builtin types:
20    </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
21	char
22      </p></li><li class="listitem"><p>
23	signed char
24      </p></li><li class="listitem"><p>
25	unsigned char
26      </p></li><li class="listitem"><p>
27	signed short
28      </p></li><li class="listitem"><p>
29	signed int
30      </p></li><li class="listitem"><p>
31	signed long
32      </p></li><li class="listitem"><p>
33	unsigned short
34      </p></li><li class="listitem"><p>
35	unsigned int
36      </p></li><li class="listitem"><p>
37	unsigned long
38      </p></li><li class="listitem"><p>
39	bool
40      </p></li><li class="listitem"><p>
41	wchar_t
42      </p></li><li class="listitem"><p>
43	float
44      </p></li><li class="listitem"><p>
45	double
46      </p></li><li class="listitem"><p>
47	long double
48      </p></li></ul></div><p>
49      These fundamental types are always available, without having to
50      include a header file. These types are exactly the same in
51      either C++ or in C.
52    </p><p>
53      Specializing parts of the library on these types is prohibited:
54      instead, use a POD.
55    </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    The header <code class="filename">&lt;limits&gt;</code> defines
57    traits classes to give access to various implementation
58    defined-aspects of the fundamental types. The traits classes --
59    fourteen in total -- are all specializations of the class template
60    <code class="classname">numeric_limits</code>
61    and defined as follows:
62    </p><pre class="programlisting">
63   template&lt;typename T&gt;
64     struct class
65     {
66       static const bool is_specialized;
67       static T max() throw();
68       static T min() throw();
69
70       static const int digits;
71       static const int digits10;
72       static const bool is_signed;
73       static const bool is_integer;
74       static const bool is_exact;
75       static const int radix;
76       static T epsilon() throw();
77       static T round_error() throw();
78
79       static const int min_exponent;
80       static const int min_exponent10;
81       static const int max_exponent;
82       static const int max_exponent10;
83
84       static const bool has_infinity;
85       static const bool has_quiet_NaN;
86       static const bool has_signaling_NaN;
87       static const float_denorm_style has_denorm;
88       static const bool has_denorm_loss;
89       static T infinity() throw();
90       static T quiet_NaN() throw();
91       static T denorm_min() throw();
92
93       static const bool is_iec559;
94       static const bool is_bounded;
95       static const bool is_modulo;
96
97       static const bool traps;
98       static const bool tinyness_before;
99       static const float_round_style round_style;
100     };
101   </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>
102     The only change that might affect people is the type of
103     <code class="constant">NULL</code>: while it is required to be a macro,
104     the definition of that macro is <span class="emphasis"><em>not</em></span> allowed
105     to be an expression with pointer type such as
106     <code class="constant">(void*)0</code>, which is often used in C.
107    </p><p>
108     For <span class="command"><strong>g++</strong></span>, <code class="constant">NULL</code> is
109     <code class="code">#define</code>'d to be
110     <code class="constant">__null</code>, a magic keyword extension of
111     <span class="command"><strong>g++</strong></span> that is slightly safer than a plain integer.
112    </p><p>
113     The biggest problem of #defining <code class="constant">NULL</code> to be
114     something like <span class="quote">“<span class="quote">0L</span>”</span> is that the compiler will view
115     that as a long integer before it views it as a pointer, so
116     overloading won't do what you expect. It might not even have the
117     same size as a pointer, so passing <code class="constant">NULL</code> to a
118     varargs function where a pointer is expected might not even work
119     correctly if <code class="code">sizeof(NULL) &lt; sizeof(void*)</code>.
120     The G++ <code class="constant">__null</code> extension is defined so that
121     <code class="code">sizeof(__null) == sizeof(void*)</code> to avoid this problem.
122    </p><p>
123     Scott Meyers explains this in more detail in his book
124     <a class="link" href="https://www.aristeia.com/books.html" target="_top"><span class="emphasis"><em>Effective
125     Modern C++</em></span></a> and as a guideline to solve this problem
126     recommends to not overload on pointer-vs-integer types to begin with.
127    </p><p>
128     The C++ 2011 standard added the <code class="constant">nullptr</code> keyword,
129     which is a null pointer constant of a special type,
130     <code class="classname">std::nullptr_t</code>. Values of this type can be
131     implicitly converted to <span class="emphasis"><em>any</em></span> pointer type,
132     and cannot convert to integer types or be deduced as an integer type.
133     Unless you need to be compatible with C++98/C++03 or C you should prefer
134     to use <code class="constant">nullptr</code>  instead of <code class="constant">NULL</code>.
135    </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. 
136    Standard Contents
137   </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>