Title
NULL and nullptr
Status
nad
Section
[support.types]
Submitter
Sean Hunt

Created on 2010-02-07.00:00:00 last changed 164 months ago

Messages

Date: 2010-10-21.18:28:33

Proposed resolution:

[support.types]

3 The macro NULL is defined to be nullptr. is an implementation-defined C++ null pointer constant in this International Standard (4.10).196

196) Possible definitions include 0 and 0L, but not (void*)0.

[c.malloc]

7 The contents are the same as the Standard C library header <string.h>, with the change to memchr() specified in 21.6 and the macro NULL defined to be nullptr.

[date.time]

2 The contents are the same as the Standard C library header <time.h>.232 except the macro NULL, which is defined to be nullptr. The functions asctime, ctime, gmtime, and localtime are not required to avoid data races (17.6.4.8).

[c.locales]

2 The contents are the same as the Standard C library header <locale.h> except the macro NULL, which is defined to be nullptr.

[diff.null]

1 The macro NULL, defined in any of <clocale>, <cstddef>, <cstdio>, <cstdlib>, <cstring>, <ctime>, or <cwchar>, is nullptr an implementation-defined C++ null pointer constant in this International Standard (18.2).

Date: 2010-10-21.18:28:33

Rationale:

The LWG discussed the proposed resolution and several other options. There was no concensus to make this or any other changes.

Date: 2010-10-21.18:28:33

[ 2010 Pittsburgh: Moved to NAD, rationale added below. ]

Date: 2010-02-10.00:00:00

[ 2010-02-10 Chris provided wording. ]

Date: 2010-02-07.00:00:00

Currently, the [support.types]/3 allows NULL to be any null pointer constant. The footnote marks that 0 or 0L might be appropriate. However, this definition also allows the implementation to define NULL to be nullptr. This may lead to overload and conversion issues more serious than with the C++98 version:

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

void g()
{
 // calls f(int) if NULL is integral
 // calls f(void*) if NULL is nullptr
 f(NULL);
}

Possible resolutions:

  • Forbid NULL from being nullptr
  • Require NULL to be nullptr
  • Leave it as is

Making NULL nullptr would improve code correctness, and breaking backwards compatibility shouldn't be a huge concern as NULL shouldn't be used except as a null pointer constant anyways.

History
Date User Action Args
2010-10-21 18:28:33adminsetmessages: + msg1566
2010-10-21 18:28:33adminsetmessages: + msg1565
2010-10-21 18:28:33adminsetmessages: + msg1564
2010-10-21 18:28:33adminsetmessages: + msg1563
2010-02-07 00:00:00admincreate