Deutsch English Français Italiano |
<87bk39u1h3.fsf@nosuchdomain.example.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!news.misty.com!2.eu.feeder.erje.net!feeder.erje.net!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: Sun, 07 Jul 2024 00:04:40 -0700 Organization: None to speak of Lines: 36 Message-ID: <87bk39u1h3.fsf@nosuchdomain.example.com> References: <v6bavg$3pu5i$1@dont-email.me> <20240706054641.175@kylheku.com> <v6bi4m$3qvgh$1@dont-email.me> <v6d73i$6r8h$3@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Date: Sun, 07 Jul 2024 09:04:40 +0200 (CEST) Injection-Info: dont-email.me; posting-host="31bef4326a7de5d231f958bc2ab73da5"; logging-data="260953"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18hXOF9WbWx9X0JCP0rlm8J" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:FZITP64ql+7i/0taAHG/CgIg+ck= sha1:xWYW1vKvrocUfN/nYB+G7btjgVQ= Bytes: 2432 Lawrence D'Oliveiro <ldo@nz.invalid> writes: > On Sat, 6 Jul 2024 14:51:19 +0100, bart wrote: >> Using actual zero for a pointer value is crass. This wouldn't work for >> example: >> >> char *p = 3; > > But of course this does: > > char *p = 0; > > From the C23 spec, I found this footnote in §6.6: > > A named constant or compound literal constant of integer type and > value zero is a null pointer constant. A named constant or > compound literal constant with a pointer type and a value null is > a null pointer but not a null pointer constant; it may only be > used to initialize a pointer object if its type implicitly > converts to the target type. > > That first sentence is so important, you’d think it would be in the main > text somewhere. The definition of "null pointer constant" is in N3220 6.3.2.3, (Conversions, Other operands, Pointers): An integer constant expression with the value 0, such an expression cast to type void *, or the predefined constant nullptr is called a *null pointer constant*. 6.6 makes it clear that named constants and compound literal constants of integer type are integer constant expressions. -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com void Void(void) { Void(); } /* The recursive call of the void */