Path: csiph.com!weretis.net!feeder8.news.weretis.net!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c++ Subject: Re: NULL versus 0 Date: Mon, 27 Sep 2021 11:32:41 -0700 Organization: None to speak of Lines: 42 Message-ID: <87bl4dkgxi.fsf@nosuchdomain.example.com> References: <21138a34-469b-4c7a-9ef1-e9307ba52673n@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: reader02.eternal-september.org; posting-host="39ff22a84492e5ec37e25bfe4071ee27"; logging-data="14470"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19UsK9XYDeIEKlfgYH5ddBi" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:Zjoujy1ILI6HcZZECGFE+rxE2qw= sha1:0ZbKu9FAOZ37HE59ZfXynwOivEw= Xref: csiph.com comp.lang.c++:81626 "Alf P. Steinbach" writes: > On 27 Sep 2021 08:32, Bo Persson wrote: >> On 2021-09-27 at 07:47, Juha Nieminen wrote: >>> Paavo Helde 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.) >>> >> It just says >> "The macro NULL is an implementation-defined null pointer constant." >> And then a footnote saying that 0 is one possibility, but (void*)0 >> is not. > > C++17 §7.11/1: > ❝A /null pointer constant/ is an integer literal with value zero or a > prvalue of type `std::nullptr_t`.❞ > > As I recall the insistence on a null pointer constant being a literal > was introduced in C++11; the C++03 definition was > > C++03 §4.10/1: > ❝A /null pointer constant/ is an integral constant expression rvalue > of integer type that evaluates to zero.❞ > > A subtle but perhaps important change. Perhaps subtle, but I don't think it's all that important. It means that (2-2) is a null pointer constant in C++03 but not in C++17 -- but I can't think of any good reason to use (2-2) as a null pointer constant outside of deliberately contrived code. Of course the addition of `std::nullptr_t` is important. -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for Philips void Void(void) { Void(); } /* The recursive call of the void */