C++0x: Null pointer

From Dwarf Wiki
Jump to: navigation, search

For detail description of the feature, please refer to:

http://en.wikipedia.org/wiki/C%2B%2B0x#Null_pointer

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2431.pdf


Overview

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

none.

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.


Example

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>