Groups | Search | Server Info | Keyboard shortcuts | Login | Register
Groups > comp.lang.c > #387533
| Path | csiph.com!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Tim Rentsch <tr.17687@z991.linuxsc.com> |
| Newsgroups | comp.lang.c |
| Subject | Re: question about nullptr |
| Date | Mon, 12 Aug 2024 17:42:39 -0700 |
| Organization | A noiseless patient Spider |
| Lines | 58 |
| Message-ID | <861q2t1ce8.fsf@linuxsc.com> (permalink) |
| 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> <v6n36o$239h6$2@dont-email.me> |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Injection-Date | Tue, 13 Aug 2024 02:42:40 +0200 (CEST) |
| Injection-Info | dont-email.me; posting-host="7741d78d7fa92162b25738c81b1a0845"; logging-data="3733603"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18GL9trHk12ztjftE/RLhIlMMKOUz3oZn0=" |
| User-Agent | Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) |
| Cancel-Lock | sha1:jcdiLuso/+8/B40trKwcUVYkoH8= sha1:IsDVrq0yt4f9gnzsB/XUZcXkaZ8= |
| Xref | csiph.com comp.lang.c:387533 |
Show key headers only | View raw
James Kuyper <jameskuyper@alumni.caltech.edu> writes:
> On 7/10/24 17:23, Keith Thompson wrote:
>
>> 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.
>
> I think you're right about that.
The compound literal is not a null pointer constant. I didn't
say it is. The null pointer constant is (long)0.0, like my
earlier posting pointed out.
> "An integer constant expression132) ... shall only have operands
> that are ... compound literal constants of arithmetic type that
> are the immediate operands of casts. ... Cast operators in an
> integer constant expression shall only convert arithmetic types to
> integer types, ...", so (long)0.0 is permitted."
>
> While (void*) looks like a cast, in this context it is a compound
> literal of pointer type, which is not allowed. [..]
Don't be silly. The compound literal works just fine in the
context I mentioned for it:
#include <stdio.h>
int
main(){
printf( " null pointer : %p\n", (void*){ (long)0.0 } );
return 0;
}
Compile it for yourself if you don't believe me.
Back to comp.lang.c | Previous | Next — Next in thread | Find similar
Re: question about nullptr Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-08-12 17:42 -0700 Re: question about nullptr Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-08-12 18:33 -0700
csiph-web