Deutsch   English   Français   Italiano  
<90c2181ae4c7aac8f17f076093923d5b357c43aa@i2pn2.org>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!weretis.net!feeder9.news.weretis.net!news.nk.ca!rocksolid2!i2pn2.org!.POSTED!not-for-mail
From: Richard Damon <richard@damon-family.org>
Newsgroups: comp.lang.c
Subject: Re: question about nullptr
Date: Sat, 6 Jul 2024 10:39:57 -0400
Organization: i2pn2 (i2pn.org)
Message-ID: <90c2181ae4c7aac8f17f076093923d5b357c43aa@i2pn2.org>
References: <v6bavg$3pu5i$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 6 Jul 2024 14:39:57 -0000 (UTC)
Injection-Info: i2pn2.org;
	logging-data="2360217"; mail-complaints-to="usenet@i2pn2.org";
	posting-account="diqKR1lalukngNWEqoq9/uFtbkm5U+w3w6FQ0yesrXg";
User-Agent: Mozilla Thunderbird
In-Reply-To: <v6bavg$3pu5i$1@dont-email.me>
X-Spam-Checker-Version: SpamAssassin 4.0.0
Content-Language: en-US
Bytes: 2075
Lines: 26

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.