Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      nullptr_t

      From cppreference.com
      <c‎ |types
       
       
       
      Defined in header<stddef.h>
      typedef typeof(nullptr) nullptr_t;
      (since C23)

      nullptr_t is the type of the predefined null pointer constant,nullptr. It is a distinct type that is not itself a pointer type. It can beimplicitly converted to any pointer type orbool, and the result is the null pointer value of that type orfalse respectively. No type other thannullptr_t itself can be converted or explicitly cast tonullptr_t.

      sizeof(nullptr_t) andalignof(nullptr_t) are equal tosizeof(void*) andalignof(void*) respectively.

      nullptr_t has only one valid value, i.e.,nullptr. The object representation ofnullptr is same as that of(void*)0. If anlvalue conversion produces anullptr_t value with a different object representation, the behavior is undefined.

      [edit]Example

      Demonstrate thatnullptr_t is a distinct type.

      Run this code
      #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);}

      Output:

      void*othernullptr_t

      [edit]References

      • C23 standard (ISO/IEC 9899:2024):
      • 7.21.2 The nullptr_t type (p: 315-316)

      [edit]See also

      implementation-defined null pointer constant
      (macro constant)[edit]
      C++ documentation fornullptr_t
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=c/types/nullptr_t&oldid=172487"

      [8]ページ先頭

      ©2009-2025 Movatter.jp