Deutsch English Français Italiano |
<v6ejth$e2b8$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: bart <bc@freeuk.com> Newsgroups: comp.lang.c Subject: Re: question about nullptr Date: Sun, 7 Jul 2024 18:40:02 +0100 Organization: A noiseless patient Spider Lines: 32 Message-ID: <v6ejth$e2b8$1@dont-email.me> 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; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Sun, 07 Jul 2024 19:40:01 +0200 (CEST) Injection-Info: dont-email.me; posting-host="f75d1ea82b211cd880bb79514b946f37"; logging-data="461160"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ACE3b7jUBwwfXYbWU+uae" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:u8B5knoF97u8s0tIfkXvdqNex0c= Content-Language: en-GB In-Reply-To: <v6d73i$6r8h$3@dont-email.me> Bytes: 2184 On 07/07/2024 05:55, Lawrence D'Oliveiro wrote: > 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. It doesn't tell the full story, as you can have any arbitrary expression of such terms that results in a suitable value: char* p = width*height; This is valid if width/height are enums and that area calculation yields zero. But update values slightly and it no longer compiles.