Re: question about nullptr

Liste des GroupesRevenir à cl c 
Sujet : Re: question about nullptr
De : ben (at) *nospam* bsb.me.uk (Ben Bacarisse)
Groupes : comp.lang.c
Date : 08. Jul 2024, 01:42:02
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <87jzhwu5v9.fsf@bsb.me.uk>
References : 1 2 3 4 5 6 7 8
User-Agent : Gnus/5.13 (Gnus v5.13)
scott@slp53.sl.home (Scott Lurndal) writes:

Ben Bacarisse <ben@bsb.me.uk> writes:
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.
>
the digit zero is context dependent, which makes it ambiguous.

Ah.  I thought we were talking about a pointer context so I thought you
meant that using 0 in a pointer context was ambiguous.  In

  char *p = 0;

the 0 is not ambiguous (i.e. open to more than one meaning).  It's open
to being misunderstood by people who don't know C, but that true of the
'char', the '*' and the '=' (and possibly the 'p' and the ';' too).

I.e. it can either be a  null pointer or the value zero
depending on context, which makes it ambiguous to the casual
reader.  Particularly when reading code that someone
else has written.  NULL makes the programmers intent crystal
clear.

That's a rather niche readership -- one that might consider

  char *p = 0;

unclear.  Do you want such people reading your C code with a view to
working on it?

I find myself completely out of step with many posters here about
"explicit code" should look like.  I think

  char *p = 0;

is explicit enough and, in fact, I consider it a plus point if someone
reading it goes "hey, what's going on here?" and ends up learning that 0
is null pointer constant in C.  They may, along the way, learn a few
other things that they should also know before fiddling with the code.
At the very least, they will have learnt that they don't know it all.

--
Ben.

Date Sujet#  Auteur
6 Jul 24 * question about nullptr125Thiago Adams
6 Jul 24 +- Re: question about nullptr1Bonita Montero
6 Jul 24 +- Re: question about nullptr1John McCue
6 Jul 24 +* Re: question about nullptr104Kaz Kylheku
6 Jul 24 i+* Re: question about nullptr86Janis Papanagnou
6 Jul 24 ii+* Re: question about nullptr2Janis Papanagnou
6 Jul 24 iii`- Re: question about nullptr1Janis Papanagnou
6 Jul 24 ii+* Re: question about nullptr2Andrey Tarasevich
7 Jul 24 iii`- Re: question about nullptr1Tim Rentsch
6 Jul 24 ii+* Re: question about nullptr2bart
7 Jul 24 iii`- Re: question about nullptr1Keith Thompson
6 Jul 24 ii+* Re: question about nullptr9Chris M. Thomasson
6 Jul 24 iii+* Re: question about nullptr3Chris M. Thomasson
7 Jul 24 iiii`* Re: question about nullptr2Lawrence D'Oliveiro
9 Jul 24 iiii `- Re: question about nullptr1Chris M. Thomasson
6 Jul 24 iii+- Re: question about nullptr1Richard Damon
7 Jul 24 iii+* Re: question about nullptr3James Kuyper
7 Jul 24 iiii`* Re: question about nullptr2Keith Thompson
7 Jul 24 iiii `- Re: question about nullptr1Chris M. Thomasson
7 Jul 24 iii`- Re: question about nullptr1Lawrence D'Oliveiro
7 Jul 24 ii+- Re: question about nullptr1Kaz Kylheku
7 Jul 24 ii`* Re: question about nullptr69Ben Bacarisse
7 Jul 24 ii +- Re: question about nullptr1Tim Rentsch
7 Jul 24 ii +- Re: question about nullptr1Tim Rentsch
7 Jul 24 ii +- Re: question about nullptr1Kaz Kylheku
7 Jul 24 ii `* Re: question about nullptr65Ben Bacarisse
8 Jul 24 ii  +* Re: question about nullptr37Keith Thompson
8 Jul 24 ii  i+- Re: question about nullptr1Janis Papanagnou
8 Jul 24 ii  i+* Re: question about nullptr27Michael S
9 Jul 24 ii  ii+* Re: question about nullptr12Chris M. Thomasson
9 Jul 24 ii  iii`* Re: question about nullptr11Michael S
9 Jul 24 ii  iii `* Re: question about nullptr10Tim Rentsch
9 Jul 24 ii  iii  +* Re: question about nullptr6Thiago Adams
9 Jul 24 ii  iii  i+* Re: question about nullptr3Tim Rentsch
9 Jul 24 ii  iii  ii`* Re: question about nullptr2Thiago Adams
9 Jul 24 ii  iii  ii `- Re: question about nullptr1Tim Rentsch
10 Jul 24 ii  iii  i`* Re: question about nullptr2Kaz Kylheku
10 Jul 24 ii  iii  i `- Re: question about nullptr1Thiago Adams
9 Jul 24 ii  iii  `* Re: question about nullptr3Michael S
9 Jul 24 ii  iii   +- Re: question about nullptr1Tim Rentsch
9 Jul 24 ii  iii   `- Re: question about nullptr1David Brown
9 Jul 24 ii  ii+* Re: question about nullptr4Kaz Kylheku
9 Jul 24 ii  iii`* Re: question about nullptr3Michael S
9 Jul 24 ii  iii +- Re: question about nullptr1Kaz Kylheku
9 Jul 24 ii  iii `- Re: question about nullptr1Tim Rentsch
9 Jul 24 ii  ii`* Re: question about nullptr10Tim Rentsch
9 Jul 24 ii  ii `* Re: question about nullptr9Keith Thompson
9 Jul 24 ii  ii  +- Re: question about nullptr1Chris M. Thomasson
10 Jul 24 ii  ii  `* Re: question about nullptr7Tim Rentsch
10 Jul 24 ii  ii   `* Re: question about nullptr6Keith Thompson
11 Jul 24 ii  ii    +* Re: question about nullptr3James Kuyper
13 Aug 24 ii  ii    i`* Re: question about nullptr2Tim Rentsch
13 Aug 24 ii  ii    i `- Re: question about nullptr1Keith Thompson
13 Aug 24 ii  ii    `* Re: question about nullptr2Tim Rentsch
13 Aug 24 ii  ii     `- Re: question about nullptr1Keith Thompson
8 Jul 24 ii  i+- Re: question about nullptr1Keith Thompson
9 Jul 24 ii  i`* Re: question about nullptr7Andrey Tarasevich
9 Jul 24 ii  i +* Re: question about nullptr2Andrey Tarasevich
11 Jul 24 ii  i i`- Re: question about nullptr1Lawrence D'Oliveiro
9 Jul 24 ii  i `* Re: question about nullptr4Keith Thompson
10 Jul 24 ii  i  `* Re: question about nullptr3Tim Rentsch
10 Jul 24 ii  i   `* Re: question about nullptr2Keith Thompson
12 Aug 24 ii  i    `- Re: question about nullptr1Tim Rentsch
8 Jul 24 ii  `* Re: question about nullptr27Ben Bacarisse
8 Jul 24 ii   +* Re: question about nullptr24Kaz Kylheku
8 Jul 24 ii   i+* Re: question about nullptr22Janis Papanagnou
8 Jul 24 ii   ii+* Re: question about nullptr19Ben Bacarisse
8 Jul 24 ii   iii+* Re: question about nullptr12Janis Papanagnou
8 Jul 24 ii   iiii`* Re: question about nullptr11Ben Bacarisse
8 Jul 24 ii   iiii `* Re: question about nullptr10Janis Papanagnou
9 Jul 24 ii   iiii  `* Re: question about nullptr9Ben Bacarisse
10 Jul 24 ii   iiii   `* Re: question about nullptr8Janis Papanagnou
11 Jul 24 ii   iiii    `* Re: question about nullptr7Ben Bacarisse
12 Jul 24 ii   iiii     `* Re: question about nullptr6Janis Papanagnou
13 Jul 24 ii   iiii      +* Re: question about nullptr3Ben Bacarisse
13 Jul 24 ii   iiii      i`* Re: question about nullptr2Janis Papanagnou
15 Jul 24 ii   iiii      i `- Re: question about nullptr1Ben Bacarisse
13 Jul 24 ii   iiii      +- Re: question about nullptr1Janis Papanagnou
17 Jul 24 ii   iiii      `- Re: question about nullptr1Tim Rentsch
9 Jul 24 ii   iii`* Re: question about nullptr6Kaz Kylheku
9 Jul 24 ii   iii +- Re: question about nullptr1Chris M. Thomasson
9 Jul 24 ii   iii `* Re: question about nullptr4Ben Bacarisse
11 Jul 24 ii   iii  `* Re: question about nullptr3Chris M. Thomasson
11 Jul 24 ii   iii   `* Re: question about nullptr2Ben Bacarisse
11 Jul 24 ii   iii    `- Re: question about nullptr1Chris M. Thomasson
11 Jul 24 ii   ii`* Re: question about nullptr2Lawrence D'Oliveiro
12 Jul 24 ii   ii `- Re: question about nullptr1Janis Papanagnou
8 Jul 24 ii   i`- Re: question about nullptr1Richard Damon
8 Jul 24 ii   `* Re: question about nullptr2James Kuyper
9 Jul 24 ii    `- Re: question about nullptr1Kaz Kylheku
6 Jul 24 i+* Re: question about nullptr4bart
7 Jul 24 ii`* Re: question about nullptr3Lawrence D'Oliveiro
7 Jul 24 ii +- Re: question about nullptr1Keith Thompson
7 Jul 24 ii `- Re: question about nullptr1bart
12 Jul 24 i`* Re: question about nullptr13Richard Harnden
12 Jul 24 i +* Re: question about nullptr4Kaz Kylheku
13 Jul 24 i i`* Re: question about nullptr3Kaz Kylheku
13 Jul 24 i i +- Re: question about nullptr1James Kuyper
13 Jul 24 i i `- Re: question about nullptr1Keith Thompson
14 Jul 24 i +- Re: question about nullptr1Tim Rentsch
16 Jul 24 i `* Re: question about nullptr7Lawrence D'Oliveiro
6 Jul 24 `* Re: question about nullptr18Richard Damon

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal