Deutsch English Français Italiano |
<87plrpt4du.fsf@bsb.me.uk> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse <ben@bsb.me.uk> Newsgroups: comp.lang.c Subject: Re: question about nullptr Date: Sun, 07 Jul 2024 19:59:25 +0100 Organization: A noiseless patient Spider Lines: 55 Message-ID: <87plrpt4du.fsf@bsb.me.uk> References: <v6bavg$3pu5i$1@dont-email.me> <20240706054641.175@kylheku.com> <v6bfi1$3qn4u$1@dont-email.me> <l9ciO.7$cr5e.2@fx05.iad> <877cdyuq0f.fsf@bsb.me.uk> <2ckiO.19403$7Ej.4487@fx46.iad> MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Sun, 07 Jul 2024 20:59:26 +0200 (CEST) Injection-Info: dont-email.me; posting-host="213b794f72069ae5495c2f80bfa9f0a2"; logging-data="480838"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+M93Bbfh4gwjBT0aCV5YCJ+BU9q3m1H1I=" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:mpTN0j76MNd3UpDVE/XayaAvsHs= sha1:yc8/p++Uty1QcktOp8XkS8it/AM= X-BSB-Auth: 1.4288a306a33759b0342b.20240707195925BST.87plrpt4du.fsf@bsb.me.uk Bytes: 3460 scott@slp53.sl.home (Scott Lurndal) writes: > Ben Bacarisse <ben@bsb.me.uk> writes: >>scott@slp53.sl.home (Scott Lurndal) writes: >> >>> Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes: >>>>On 06.07.2024 14:54, Kaz Kylheku wrote: >>>>> On 2024-07-06, Thiago Adams <thiago.adams@gmail.com> wrote: >>>>>> If you were creating C code today and could use a C23 compiler, would >>>>>> you use nullptr instead of NULL? >>>>> >>>>> In greenfield projects under my dictatorship, I use 0, as in: >>>>> >>>>> char *p = 0; >>>>> >>>>> I was still 20 something when I (easily) wrapped my head around the 0 >>>>> null pointer constant, and have not had any problems with it. >>>>> Once I learned the standard-defined truth about null pointer constants, >>>>> and their relationship to the NULL macro, I dropped NULL like a hot >>>>> potato, and didn't look back (except when working in code bases that use >>>>> NULL). >>>> >>>>We also used 0 as "universal" pointer value regularly without >>>>problems. >> >>I also like to use 0, but I'm not sure I could say exactly why. Maybe >>because of pre-C exposure (B and BCPL). >> >>> Whereas I spent 6 years programming on an architecture[*] where a >>> null pointer was represented in hardware by the value 0xc0eeeeee. I always >>> use the NULL macro in both C and C++ code. >> >>I'm sure you know (but maybe some other readers might not) that that >>does not stop one using 0 in C source code. Whatever a null pointer >>"really" is on some hardware, 0 must work in C, including in comparisons >>with == and !=. You can have > > Yes. However, I consider that ambiguous, I prefer to be explicit and > use NULL or nullptr. In what sense is using 0 ambiguous? I can't see it. Ambiguous and explicit are not opposites, so many you did not mean to say that 0 is ambiguous. Its use does require the reader to know the role played by zero integer constant expressions in C. But then NULL might be defined to be 0. It /looks/ more like a pointer but there's lots of code that erroneously assumes that it is, presumably because of that deceptive look. (nullptr is another matter.) Do you always cast NULL to a pointer in those (admittedly rare) cases when one needs to? I think it's easier to remember to do that with 0. -- Ben.