| Deutsch English Français Italiano |
|
<87ikw5gpsn.fsf@nosuchdomain.example.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: question about nullptr
Date: Mon, 12 Aug 2024 18:44:08 -0700
Organization: None to speak of
Lines: 80
Message-ID: <87ikw5gpsn.fsf@nosuchdomain.example.com>
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>
<87plrpt4du.fsf@bsb.me.uk> <9bCiO.7108$sXW9.3805@fx41.iad>
<877cdwu9s1.fsf@nosuchdomain.example.com>
<20240708222804.00001654@yahoo.com> <86le2b9ru6.fsf@linuxsc.com>
<8734ojxlg7.fsf@nosuchdomain.example.com> <86msmp8fld.fsf@linuxsc.com>
<87cynluekl.fsf@nosuchdomain.example.com> <86plqdz0q3.fsf@linuxsc.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Tue, 13 Aug 2024 03:44:08 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="75b586a96d8f13b1a18286173fed3ce1";
logging-data="3733360"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19l5tMzcLz0hbQS0R35ZlwL"
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:CvcViwZWwLLk+tadmZ+m4KMjl/Q=
sha1:wc0XB/bHnO3tk9xjET/lPGCMFyg=
Bytes: 4180
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>>> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>>>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>>>> [...]
>>>>> This posting has inspired me to try using (long)0.0
>>>>> whenever a null pointer constant is needed. As for
>>>>> example
>>>>>
>>>>> (void*){ (long)0.0 }
>>>>>
>>>>> as an argument to a variadic function where a pointer
>>>>> is expected.
>>>>
>>>> But surely ((void*)('/'/'/'-'/'/'/')) is more elegant.
>>>
>>> Surely not. Furthermore the form I showed has a point,
>>> whereas this example is roughly the equivalent of a
>>> first grade knock-knock joke.
>>
>> I was of course joking. I assumed you were as well.
>>
>> What is the point of (void*){ (long)0.0 }? I don't believe it's a
>> null pointer constant even in C23.
>
> The null pointer constant is (long)0.0, which it must be for the
> compound literal to work.
Depending on the context, a null pointer constant is not necessary for
the compound literal to work. Adapting your example from elsethread :
#include <stdio.h>
int main(void) {
void *np = (long)0.0;
printf(" null pointer : %p\n", (void*){ np });
}
> Besides making it obvious that (long)0.0
> is a null pointer constant, the compound literal is safer than
> using just a cast.
I fail to see how it's safer.
>> My example is.
>
> Your example actually has two null pointer constants:
It actually has four, but how is that relevant?
I wrote :
But surely ((void*)('/'/'/'-'/'/'/')) is more elegant.
The following are all null pointer constants :
'/'/'/'-'/'/'/'
('/'/'/'-'/'/'/')
(void*)('/'/'/'-'/'/'/')
((void*)('/'/'/'-'/'/'/'))
But I never said otherwise. I merely said that my example (the
outermost expression) is an NPC.
> the
> expression being casted, and the full expression casting a null
> pointer constant to (void*). But in neither case is that especially
> obvious. Also the expression you wrote is less safe. For example,
> if it had been written ((void*)('/'/'/'+'/'/'/')), the result would
> still be legal C, and compile without problem, but would very likely
> not be what was desired. By contrast, if the compound literal had
> been written (void*){ (long)1.0 }, it simply would not give a clean
> compile, indicating that something is likely askew.
One more time: It was a joke. I thought that was obvious when I wrote
it. If it wasn't, you know now.
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */