blob: ea058783a856f6cae07a7e7b290d58c4a95d9145 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
<h1 id="firstHeading" class="firstHeading">nullptr_t</h1> <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code><stddef.h></code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl t-since-c23"> <td> <pre data-language="c">typedef typeof(nullptr) nullptr_t;</pre>
</td> <td class="t-dcl-nopad"> </td> <td> <span class="t-mark-rev t-since-c23">(since C23)</span> </td> </tr> </table> <p><code>nullptr_t</code> is the type of the predefined null pointer constant, <a href="../language/nullptr" title="c/language/nullptr"><code>nullptr</code></a>. It is a distinct type that is not itself a pointer type. It can be <a href="../language/conversion" title="c/language/conversion">implicitly converted</a> to any pointer type or <code>bool</code>, and the result is the null pointer value of that type or <code>false</code> respectively. No type other than <code>nullptr_t</code> itself can be converted or explicitly cast to <code>nullptr_t</code>.</p>
<p><code>sizeof(nullptr_t)</code> and <code>alignof(nullptr_t)</code> are equal to <code>sizeof(void*)</code> and <code>alignof(void*)</code> respectively.</p>
<p><code>nullptr_t</code> has only one valid value, i.e., <code>nullptr</code>. The object representation of <code>nullptr</code> is same as that of <code>(void*)0</code>. If a program produces a <code>nullptr_t</code> value with a different object representation, the behavior is undefined.</p>
<h3 id="Example"> Example</h3> <div class="t-example">
<p>Demonstrate that <code>nullptr_t</code> is a distinct type.</p>
<div class="c source-c"><pre data-language="c">#include <stddef.h>
#include <stdio.h>
#define DETECT_NULL_POINTER_CONSTANT(e) \
_Generic(e, \
void* : puts("void*"), \
nullptr_t : puts("nullptr_t"), \
default : puts("other") \
)
int main()
{
DETECT_NULL_POINTER_CONSTANT(((void*)0));
DETECT_NULL_POINTER_CONSTANT(0);
DETECT_NULL_POINTER_CONSTANT(nullptr);
}</pre></div> <p>Output:</p>
<div class="text source-text"><pre data-language="c">void*
other
nullptr_t</pre></div> </div> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="null" title="c/types/NULL"> <span class="t-lines"><span>NULL</span></span></a></div> </td> <td> implementation-defined null pointer constant <br> <span class="t-mark">(macro constant)</span> </td>
</tr> <tr class="t-dsc"> <td colspan="2"> <span><a href="https://en.cppreference.com/w/cpp/types/nullptr_t" title="cpp/types/nullptr t">C++ documentation</a></span> for <code>nullptr_t</code> </td>
</tr> </table> <div class="_attribution">
<p class="_attribution-p">
© cppreference.com<br>Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.<br>
<a href="https://en.cppreference.com/w/c/types/nullptr_t" class="_attribution-link">https://en.cppreference.com/w/c/types/nullptr_t</a>
</p>
</div>
|