From 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 7 Apr 2024 13:41:34 -0500 Subject: new repository --- devdocs/c/language%2Fnullptr.html | 59 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 devdocs/c/language%2Fnullptr.html (limited to 'devdocs/c/language%2Fnullptr.html') diff --git a/devdocs/c/language%2Fnullptr.html b/devdocs/c/language%2Fnullptr.html new file mode 100644 index 00000000..9c5d8a87 --- /dev/null +++ b/devdocs/c/language%2Fnullptr.html @@ -0,0 +1,59 @@ +

Predefined null pointer constant (since C23) +

Syntax

+ +
nullptr (since C23)

Explanation

The keyword nullptr denotes a predefined null pointer constant. It is a non-lvalue of type nullptr_t. nullptr can be converted to a pointer types or bool, where the result is the null pointer value of that type or false respectively.

+

Keywords

nullptr

+

Example

+

Demonstrates that a copy of nullptr can also be used as a null pointer constant.

+
#include <stddef.h>
+#include <stdio.h>
+ 
+void g(int*)
+{
+    puts("Function g called");
+}
+ 
+#define DETECT_NULL_POINTER_CONSTANT(e) \
+    _Generic(e,                         \
+        void* : puts("void*"),          \
+        nullptr_t : puts("nullptr_t"),  \
+        default : puts("integer")       \
+    )
+ 
+int main()
+{
+    g(nullptr); // OK
+    g(NULL); // OK
+    g(0); // OK
+ 
+    auto cloned_nullptr = nullptr;
+    g(cloned_nullptr); // OK
+ 
+    [[maybe_unused]] auto cloned_NULL = NULL;
+//  g(cloned_NULL); // implementation-defined: maybe OK
+ 
+    [[maybe_unused]] auto cloned_zero = 0;
+//  g(cloned_zero); // Error
+ 
+    DETECT_NULL_POINTER_CONSTANT(((void*)0));
+    DETECT_NULL_POINTER_CONSTANT(0);
+    DETECT_NULL_POINTER_CONSTANT(nullptr);
+    DETECT_NULL_POINTER_CONSTANT(NULL); // implementation-defined
+}

Possible output:

+
Function g called
+Function g called
+Function g called
+Function g called
+void*
+integer
+nullptr_t
+void*

See also

+ + +
implementation-defined null pointer constant
(macro constant)
+
(C23)
the type of the predefined null pointer constant nullptr
(typedef)
C++ documentation for nullptr
+

+ © cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
+ https://en.cppreference.com/w/c/language/nullptr +

+
-- cgit v1.2.3