C++0x: Null pointer

From wiki.dwarfstd.org
Jump to navigation Jump to search

For detail description of the feature, please refer to:




nullptr is a literal denoting the null pointer. It does not have int type. It has a type that is implicitly convertible and comparable to any pointer type or pointer-to-member type. It is not implicitly convertible or comparable to integer types. The type of nullptr is decltype(nullptr)

#define NULL 0

char *p = NULL;     // 0 can still be used as NULL, for backward compatibility
int  *q = nullptr;  // C++0x nullptr

void f(int);
void f(char*);

f(NULL);            // call f(int), undesirable
f(nullptr);         // call f(char*)

void g(int);
f(nullptr);         // error: nullptr can not implicitly convert to int.

Proposed change to DWARF


If necessary, use the DW_TAG_unspecified_type to describe the type of nullptr. But we do not expect to see much use of this type in real programs.


To describe the nullptr:

<1><  xxx>      DW_TAG_unspecified_type
                DW_AT_name                  decltype(nullptr)
<1><  ###>      DW_TAG_constant
                DW_AT_name                  nullptr
                DW_AT_type                  <xxx>