Path: csiph.com!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c Subject: Re: question about nullptr Date: Sat, 13 Jul 2024 17:21:56 -0700 Organization: A noiseless patient Spider Lines: 45 Message-ID: <867cdo7rh7.fsf@linuxsc.com> References: <20240706054641.175@kylheku.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Sun, 14 Jul 2024 02:21:57 +0200 (CEST) Injection-Info: dont-email.me; posting-host="5c27e5a18f871cdaf0e390dfc4b4abb1"; logging-data="4008515"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/S7Mnjh+KVB37AyseMxZwxZBwBFRZFQgk=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:qrO4/eAevNqdqqlsFMfzxdgKLs4= sha1:H6qaTtzqR5fgesadOAzhIyOrHVA= Xref: csiph.com comp.lang.c:387143 Richard Harnden writes: > 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). > > I don't understand why you wouldn't use NULL. The arguments I have heard for using NULL sound a lot like the reason given for climbing Mount Everest. (Incidentally the person who said that died trying to climb the mountain.) > If it's a pointer: NULL In most cases I would use 0, converted to an appropriate pointer type using a compound literal if necessary. > If it's an integer: 0 Yes in almost all cases. > If it's a double: 0.0 In most cases where an integral value is needed for a floating-point type I would use an integer. Sometimes a judicious 0. or 1. is needed to force conversion. > If it's a char: '\0' The integer constant '\0' reminds me of the short poem about a purple cow.