diff options
| author | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
| commit | 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch) | |
| tree | f1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/c/types%2Fnullptr_t.html | |
new repository
Diffstat (limited to 'devdocs/c/types%2Fnullptr_t.html')
| -rw-r--r-- | devdocs/c/types%2Fnullptr_t.html | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/devdocs/c/types%2Fnullptr_t.html b/devdocs/c/types%2Fnullptr_t.html new file mode 100644 index 00000000..ea058783 --- /dev/null +++ b/devdocs/c/types%2Fnullptr_t.html @@ -0,0 +1,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> |
