]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/libstdc++-v3/contrib/libstdc++-v3-4.3.3/doc/html/manual/bk01pt02ch04s03.html
update
[l4.git] / l4 / pkg / libstdc++-v3 / contrib / libstdc++-v3-4.3.3 / doc / html / manual / bk01pt02ch04s03.html
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>NULL</title><meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /><meta name="keywords" content="&#10;      ISO C++&#10;    , &#10;      library&#10;    " /><link rel="start" href="../spine.html" title="The GNU C++ Library Documentation" /><link rel="up" href="bk01pt02ch04.html" title="Chapter 4. Types" /><link rel="prev" href="bk01pt02ch04s02.html" title="Numeric Properties" /><link rel="next" href="bk01pt02ch05.html" title="Chapter 5. Dynamic Memory" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">NULL</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="bk01pt02ch04s02.html">Prev</a> </td><th width="60%" align="center">Chapter 4. Types</th><td width="20%" align="right"> <a accesskey="n" href="bk01pt02ch05.html">Next</a></td></tr></table><hr /></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="manual.support.types.null"></a>NULL</h2></div></div></div><p>
4      The only change that might affect people is the type of
5      <code class="constant">NULL</code>: while it is required to be a macro,
6      the definition of that macro is <span class="emphasis"><em>not</em></span> allowed
7      to be <code class="constant">(void*)0</code>, which is often used in C.
8     </p><p>
9      For <span class="command"><strong>g++</strong></span>, <code class="constant">NULL</code> is
10      </p><pre class="programlisting">#define</pre><p>'d to be
11      <code class="constant">__null</code>, a magic keyword extension of
12      <span class="command"><strong>g++</strong></span>.
13     </p><p>
14      The biggest problem of #defining <code class="constant">NULL</code> to be
15      something like “<span class="quote">0L</span>” is that the compiler will view
16      that as a long integer before it views it as a pointer, so
17      overloading won't do what you expect. (This is why
18      <span class="command"><strong>g++</strong></span> has a magic extension, so that
19      <code class="constant">NULL</code> is always a pointer.)
20     </p><p>In his book <a class="ulink" href="http://www.awprofessional.com/titles/0-201-92488-9/" target="_top"><span class="emphasis"><em>Effective
21     C++</em></span></a>, Scott Meyers points out that the best way
22     to solve this problem is to not overload on pointer-vs-integer
23     types to begin with.  He also offers a way to make your own magic
24     <code class="constant">NULL</code> that will match pointers before it
25     matches integers.
26     </p><p>See 
27       <a class="ulink" href="http://www.awprofessional.com/titles/0-201-31015-5/" target="_top">the
28       Effective C++ CD example</a>
29     </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="bk01pt02ch04s02.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="bk01pt02ch04.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="bk01pt02ch05.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Numeric Properties </td><td width="20%" align="center"><a accesskey="h" href="../spine.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 5. Dynamic Memory</td></tr></table></div></body></html>