Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: bart Newsgroups: comp.lang.c Subject: Re: question about nullptr Date: Sat, 6 Jul 2024 14:51:19 +0100 Organization: A noiseless patient Spider Lines: 40 Message-ID: References: <20240706054641.175@kylheku.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sat, 06 Jul 2024 15:51:19 +0200 (CEST) Injection-Info: dont-email.me; posting-host="c37fc5164b87e9d2d37a8965ff47e68e"; logging-data="4029969"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19zTE/ZK7pWdJd1zYqPHDqk" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:YlqGsZt/pGKcjU+N0RS5zgnZ+/I= In-Reply-To: <20240706054641.175@kylheku.com> Content-Language: en-GB Bytes: 2030 On 06/07/2024 13:54, Kaz Kylheku wrote: > On 2024-07-06, Thiago Adams wrote: >> If you were creating C code today and could use a C23 compiler, would >> you use nullptr instead of NULL? > > In greenfield projects under my dictatorship, I use 0, as in: > > char *p = 0; > > I was still 20 something when I (easily) wrapped my head around the 0 > null pointer constant, and have not had any problems with it. > Once I learned the standard-defined truth about null pointer constants, > and their relationship to the NULL macro, I dropped NULL like a hot > potato, and didn't look back (except when working in code bases that use > NULL). > Using actual zero for a pointer value is crass. This wouldn't work for example: char *p = 3; Nor this: int a = 0; char *p = a; Although this does: char *p = 3/4; And this: enum {a=42, b=a}; char *p = a-b; // or a&1, but not a&2 It walks all over the language's type system, such as it is.