Sujet : Re: question about nullptr
De : jameskuyper (at) *nospam* alumni.caltech.edu (James Kuyper)
Groupes : comp.lang.cDate : 08. Jul 2024, 16:03:42
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v6gv4f$tp07$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9
User-Agent : Mozilla Thunderbird
On 7/7/24 19:42, Ben Bacarisse wrote:
scott@slp53.sl.home (Scott Lurndal) writes:
...
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?
The problem is not "char p=0;". If you're sure what type p has, there's
no problem. The problem comes with code like "p=0", where "p=NULL" would
serve to remind you that p should be a pointer, while "p=nullptr"
guarantees a diagnostic if p is not a pointer. I have fixed bugs which
would have been caught a lot earlier if nullptr had existed, and had
been the only permitted kind of null pointer constant.