Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #81668
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: NULL versus 0 |
| Date | 2021-09-29 08:52 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <sj12fl$pko$1@dont-email.me> (permalink) |
| References | (4 earlier) <87a6jzlmu6.fsf@nosuchdomain.example.com> <tcX3J.71792$VZ1.29839@fx08.iad> <871r5bkn9d.fsf@nosuchdomain.example.com> <MbQ4J.17929$d82.7537@fx21.iad> <87y27ghx5w.fsf@nosuchdomain.example.com> |
On 29/09/2021 05:34, Keith Thompson wrote: > Branimir Maksimovic <branimir.maksimovic@gmail.com> writes: >> On 2021-09-26, Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote: >>> Branimir Maksimovic <branimir.maksimovic@gmail.com> writes: >>>> On 2021-09-26, Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote: >>>>>> #define NULL (void*)0 >>>>>> simple, problem is that in C++, one have to cast from void >>>>>> and that does not works, and this is BuG in C++. >>>>> >>>>> That's not a valid definition of NULL in either C or C++. >>>>> >>>>> In C or C++, the definition has to be parenthesized to avoid parsing >>>>> errors in some contexts; >>>>> >>>>> #define NULL ((void*0) >>>>> >>>>> I'm not sure what you mean by "this is BuG in C++". A C++ >>>>> implementation that defined NULL that way would be non-conforming. >>>>> >>>> Exactly, that is why it is Bug. >>>> Thanks for correction, BTW. >>> >>> To be clear, you're saying that if any C++ implementation actually >>> defined NULL that way, it would be a bug in that implementation. >>> That's true, but I'm not aware of any implementation that actually >>> has that hypothetical bug. It can require some trivial extra work >>> for an implementation that shares headers between C and C++, but >>> implementers are well aware of the issue. >>> >> We have problem off overoading resolution then with constant zero. >> Still, despite nullptr. You can accidentally mean 0 the integer >> and have overload with pointer argument, and hav COMPILER BUG. >> This should be corrected in future standard... > > I don't know what "COMPILER BUG" you're talking about. > > Using 0 as a null pointer constant in the presence of overloaded > functions can lead to a *programming* bug. I'm not aware of any C++ > compiler that has a bug in this area (i.e., handles it in a way that's > inconsistent with what the language requires). > > That kind of programming bug can be avoided by using nullptr rather than > 0 (something that wasn't possible before C++11). > > If you're suggesting changing the language so that 0 is no longer a null > pointer constant, that would break tons of existing code. Yes. But if you want that effect, some compilers will give you it with the right flags (-Werror=zero-as-null-pointer-constant in gcc). The downside of backwards compatibility in C and C++ is that it is hard to remove features, even if they have been shown to be dangerous or replaced by significantly better alternatives. Look how long it has taken C to get rid of non-prototype function declarations - 33 years, assuming C23 comes out on plan. It would be nice if there were some way to standardise options like this in a cross-compiler fashion (perhaps with pragmas rather than compiler flags, so that they are included in the source code). The C++ and C committees [[attributes]] to standardise common extensions (gcc/clang __attribute__, MSVC declspec). So I live in hope! > > Programming bugs, compiler bugs, and language bugs are three very > different things. >
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
NULL versus 0 "das...@gmail.com" <dashley@gmail.com> - 2021-09-25 11:03 -0700
Re: NULL versus 0 Branimir Maksimovic <branimir.maksimovic@gmail.com> - 2021-09-25 18:16 +0000
Re: NULL versus 0 Paavo Helde <myfirstname@osa.pri.ee> - 2021-09-25 21:20 +0300
Re: NULL versus 0 Paavo Helde <myfirstname@osa.pri.ee> - 2021-09-25 21:32 +0300
Re: NULL versus 0 "das...@gmail.com" <dashley@gmail.com> - 2021-09-25 12:08 -0700
Re: NULL versus 0 Juha Nieminen <nospam@thanks.invalid> - 2021-09-27 05:47 +0000
Re: NULL versus 0 Bo Persson <bo@bo-persson.se> - 2021-09-27 08:32 +0200
Re: NULL versus 0 "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-09-26 23:37 -0700
Re: NULL versus 0 "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2021-09-27 10:32 +0200
Re: NULL versus 0 Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-09-27 11:32 -0700
Re: NULL versus 0 James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-09-27 15:03 -0400
Re: NULL versus 0 "see.my....@gmail.com" <see.my.homepage@gmail.com> - 2021-09-25 13:05 -0700
Re: NULL versus 0 Jorgen Grahn <grahn+nntp@snipabacken.se> - 2021-09-26 06:58 +0000
Re: NULL versus 0 Branimir Maksimovic <branimir.maksimovic@gmail.com> - 2021-09-26 07:47 +0000
Re: NULL versus 0 Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-09-26 02:15 -0700
Re: NULL versus 0 Branimir Maksimovic <branimir.maksimovic@gmail.com> - 2021-09-26 09:38 +0000
Re: NULL versus 0 Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-09-26 15:03 -0700
Re: NULL versus 0 Branimir Maksimovic <branimir.maksimovic@gmail.com> - 2021-09-29 02:29 +0000
Re: NULL versus 0 Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-09-28 20:34 -0700
Re: NULL versus 0 David Brown <david.brown@hesbynett.no> - 2021-09-29 08:52 +0200
Re: NULL versus 0 Bo Persson <bo@bo-persson.se> - 2021-09-26 13:54 +0200
Re: NULL versus 0 Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-09-26 15:17 -0700
Re: NULL versus 0 Branimir Maksimovic <branimir.maksimovic@gmail.com> - 2021-09-29 02:26 +0000
Re: NULL versus 0 Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-09-26 02:17 -0700
Re: NULL versus 0 HorseyWorsey@the_stables.com - 2021-09-26 14:20 +0000
Re: NULL versus 0 James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-09-25 17:36 -0400
Re: NULL versus 0 "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-09-26 23:05 -0700
csiph-web