Re: NULL versus 0
James Kuyper <[email protected]> Mon, 27 Sep 2021 15:01:23 -0400
| Newsgroups | alt.books.pratchett |
|---|---|
| Organization | A noiseless patient Spider |
| Message-ID | <[email protected]> |
On 9/27/21 1:47 AM, Juha Nieminen wrote: > Paavo Helde <[email protected]> wrote: >> In C++ (unlike C), NULL is a macro defined to 0, so there is no >> difference. > > Actually, many standard library implementations define NULL to be > nullptr (if we are in C++11 or newer). > > (I haven't checked the standard, but this tells me that the standard does > not mandate NULL to be defined as 0.) The mandate is quite clear: "The macro NULL is an implementation-defined null pointer constant." (17.2p3). Note that "null pointer constant" has a different definition in C++ than in C, and when compiling using C++, NULL can have a definition that meets C++ requirements rather than C requirements. In particular, that means that NULL can expand to "a prvalue of type std::nullptr_t." (7.3.11p1)