Deutsch English Français Italiano |
<v6insm$19uag$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!3.eu.feeder.erje.net!feeder.erje.net!news.in-chemnitz.de!news.swapon.de!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> Newsgroups: comp.lang.c Subject: Re: question about nullptr Date: Tue, 9 Jul 2024 00:12:21 -0700 Organization: A noiseless patient Spider Lines: 69 Message-ID: <v6insm$19uag$1@dont-email.me> References: <v6bavg$3pu5i$1@dont-email.me> <90c2181ae4c7aac8f17f076093923d5b357c43aa@i2pn2.org> <v6bt15$3svoi$1@dont-email.me> <v6iik7$1948o$1@dont-email.me> <v6iklk$19cv8$1@dont-email.me> <v6inai$19q6r$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Tue, 09 Jul 2024 09:12:23 +0200 (CEST) Injection-Info: dont-email.me; posting-host="ce358e0d0d9664a700ff455d87f9b3cd"; logging-data="1374544"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+yAmqmMmUsNoBpwD024yeY9m5co+peSr0=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:c5M0tkCfYefdaKpR3t1alUeCJ6c= Content-Language: en-US In-Reply-To: <v6inai$19q6r$1@dont-email.me> Bytes: 3834 On 7/9/2024 12:02 AM, Richard Harnden wrote: > On 09/07/2024 07:17, Chris M. Thomasson wrote: >> On 7/8/2024 10:42 PM, Richard Harnden wrote: >>> On 06/07/2024 17:57, David Brown wrote: >>>> On 06/07/2024 16:39, Richard Damon wrote: >>>>> On 7/6/24 7:49 AM, Thiago Adams wrote: >>>>>> If you were creating C code today and could use a C23 compiler, >>>>>> would you use nullptr instead of NULL? >>>>>> >>>>>> I am asking because I think I will keep using NULL. >>>>>> >>>>>> I like nullptr semantics but I don't like to introduce new element >>>>>> (nullptr) inside the code with no guarantee that the code will not >>>>>> mix both. >>>>>> >>>>>> In the past we also didn't have a guarantee we are not mixing 0 or >>>>>> NULL. >>>>>> >>>>>> I think the best scenario for a team guideline would be a style >>>>>> warning if 0 or nullptr is used and NULL to be defined as nullptr >>>>>> in a C23 compiler. >>>>>> >>>>> >>>>> The (small) problem with 0 or NULL being use is that in a context >>>>> where you THINK you are passing a pointer, but the function >>>>> actually is taking an integer value, 0 or NULL (defined as a 0) >>>>> passes the syntax check. >>>>> >>>>> If C23 REQURIED NULL to be defined as nullptr, then NULL would have >>>>> been used, but as far as I know, it is still allowed to be defined >>>>> as 0 (unless you also have POSIX compatibility). >>>>> >>>>> With POSIX Compatibility, where NULL must have the type of (void*) >>>>> you also avoid the possible error, and thus the desire to use nullptr. >>>> >>>> I hope that defining NULL as nullptr will become common - but I >>>> would be surprised to ever see it being required by C standards. >>>> >>>> The ideal would be for C libraries to define NULL as nullptr and for >>>> C compilers to support a flag like gcc's >>>> "-Wzero-as-null-pointer-constant" warning (it is currently C++ >>>> only). Then people can easily eliminate >>>> any mixup between integer 0 and null pointer constants by using that >>>> flag and either NULL or nullptr, according to taste. (And those who >>>> don't want such checks, are not required to change.) >>>> >>>> >>> >>> So, if malloc was changed to 'returns nullptr and sets errno on >>> error', will you still be able to say: >>> >>> if ( p == NULL ) ... >>> if ( !p ) ... >>> >>> ? >> >> This of a pointer p where: >> >> p = 0; > > No, I mean when p = nullptr > > p = nullptr; (0 == p == nullptr == NULL == 0) == true ? Am I missing something here? If so, here is a preemptive: Shit!