<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 1314: NULL and nullptr</title>
<meta property="og:title" content="Issue 1314: NULL and nullptr">
<meta property="og:description" content="C++ library issue. Status: NAD">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue1314.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#NAD">NAD</a> status.</em></p>
<h3 id="1314"><a href="lwg-closed.html#1314">1314</a>. <code>NULL</code> and <code>nullptr</code></h3>
<p><b>Section:</b> 17.2 <a href="https://wg21.link/support.types">[support.types]</a> <b>Status:</b> <a href="lwg-active.html#NAD">NAD</a>
 <b>Submitter:</b> Sean Hunt <b>Opened:</b> 2010-02-07 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all other</b> <a href="lwg-index.html#support.types">issues</a> in [support.types].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#NAD">NAD</a> status.</p>
<p><b>Discussion:</b></p>
<p>
Currently, the 17.2 <a href="https://wg21.link/support.types">[support.types]</a>/3 allows <code>NULL</code> to be any
null pointer constant. The footnote marks that 0 or 0L might be appropriate.
However, this definition also allows the implementation to define <code>NULL</code>
to be <code>nullptr</code>. This may lead to overload and conversion issues more
serious than with the C++98 version:
</p>

<blockquote><pre>
void f(void*);
void f(int);

void g()
{
 // calls f(int) if NULL is integral
 // calls f(void*) if NULL is nullptr
 f(NULL);
}
</pre></blockquote>

<p>
Possible resolutions:
</p>
<ul>
<li>
Forbid <code>NULL</code> from being <code>nullptr</code>
</li>
<li>
Require <code>NULL</code> to be <code>nullptr</code>
</li>
<li>
Leave it as is
</li>
</ul>

<p>
Making <code>NULL</code> <code>nullptr</code> would improve code correctness, and
breaking backwards compatibility shouldn't be a huge concern as <code>NULL</code>
shouldn't be used except as a null pointer constant anyways.
</p>

<p><i>[
2010-02-10  Chris provided wording.
]</i></p>


<p><i>[
2010 Pittsburgh:  Moved to NAD, rationale added below.
]</i></p>




<p><b>Rationale:</b></p>
<p>
The LWG discussed the proposed resolution and several other options.  There was
no concensus to make this or any other changes.
</p>


<p id="res-1314"><b>Proposed resolution:</b></p>
<p>
17.2 <a href="https://wg21.link/support.types">[support.types]</a>
</p>

<blockquote>
<p>
3 The macro <code>NULL</code> <ins>is defined to be <code>nullptr</code>.</ins> <del>is
an implementation-defined C++ null pointer constant in this International
Standard (4.10).<sup>196</sup></del>
</p>

<p><del>
196) Possible definitions include <code>0</code> and <code>0L</code>, but not
<code>(void*)0</code>.
</del></p>
</blockquote>

<p>
20.2.12 <a href="https://wg21.link/c.malloc">[c.malloc]</a>
</p>

<blockquote><p>
7 The contents are the same as the Standard C library header
<code>&lt;string.h&gt;</code>, with the change to <code>memchr()</code> specified in
21.6 <ins>and the macro <code>NULL</code> defined to be <code>nullptr</code></ins>.
</p></blockquote>


<p>
 [date.time]
</p>

<blockquote><p>
2 The contents are the same as the Standard C library header
<code>&lt;time.h&gt;</code><del>.</del><sup>232</sup> <ins>except the macro
<code>NULL</code>, which is defined to be <code>nullptr</code>.</ins> The functions
<code>asctime</code>, <code>ctime</code>, <code>gmtime</code>, and <code>localtime</code> are
not required to avoid data races (17.6.4.8).
</p></blockquote>


<p>
28.3.5 <a href="https://wg21.link/c.locales">[c.locales]</a>
</p>

<blockquote><p>
2 The contents are the same as the Standard C library header
<code>&lt;locale.h&gt;</code> <ins>except the macro <code>NULL</code>, which is defined
to be <code>nullptr</code></ins>.
</p></blockquote>

<p>
C.8.3.4 <a href="https://wg21.link/diff.null">[diff.null]</a>
</p>

<blockquote><p>
1 The macro <code>NULL</code>, defined in any of <code>&lt;clocale&gt;</code>,
<code>&lt;cstddef&gt;</code>, <code>&lt;cstdio&gt;</code>, <code>&lt;cstdlib&gt;</code>,
<code>&lt;cstring&gt;</code>, <code>&lt;ctime&gt;</code>, or <code>&lt;cwchar&gt;</code>, is
<ins>nullptr</ins> <del>an implementation-defined C++ null pointer constant in
this International Standard (18.2).</del>
</p></blockquote>






</body>
</html>
