Sujet : Re: question about nullptr
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.cDate : 09. Jul 2024, 03:32:46
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240708192708.531@kylheku.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2024-07-08, Ben Bacarisse <
ben@bsb.me.uk> wrote:
Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
>
On 08.07.2024 09:19, Kaz Kylheku wrote:
On 2024-07-07, Ben Bacarisse <ben@bsb.me.uk> wrote:
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.
And if that person is on the C or C++ langauge committee, that bit of
learning could just prevent a superfluous non-invention like nullptr.
>
What's superfluous to one is useful for others (e.g. for grep'ing
occurrences of a null-pointer value in source codes);
>
This is been suggested twice now but I'm struggling to see why that is
useful. I can see management wanting one to find all uses of a null
pointer constant to check that they have all been replaced by the
"safer" nullptr, but what's the value in searching for nullptr?
We could patch GCC to have a -Wnull-ptr-zero, which will give you a
diagnostic for every occurrence of a zero valued integer expression that
becomes a null pointer constant rather than an integer or floating-point
value (and that isn't cast to pointer type).
(If this were so hugely useful, someone woulda done it by now?)
(Of course, it would go off on occurrences of NULL where NULL
is defined as just zero; the diagnostic could be clever enough
not to go off on expressions that are the expansion descendants
of NULL, or optionally so.)
(The option would actually be useful to someone wanting to convert
0 to NULL or nullptr.)
(Just like -Wold-style-cast in GNU C++ helps coders who only want
to use static_cast and friends.)
-- TXR Programming Language: http://nongnu.org/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca