Deutsch   English   Français   Italiano  
<v6m87m$1v1rh$1@dont-email.me>

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

Path: ...!3.eu.feeder.erje.net!feeder.erje.net!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: James Kuyper <jameskuyper@alumni.caltech.edu>
Newsgroups: comp.lang.c
Subject: Re: question about nullptr
Date: Wed, 10 Jul 2024 11:09:41 -0400
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <v6m87m$1v1rh$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>
 <v6insm$19uag$1@dont-email.me> <874j8yswha.fsf@bsb.me.uk>
 <v6k6a3$1gsq2$3@dont-email.me> <v6k6ha$1gsq2$4@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 10 Jul 2024 17:09:59 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="8ee0f6de059aa2561c515748b1f9a8ec";
	logging-data="2066289"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+Dk2Y5pW7ng4tiMYRSGp5CboB/xAlCsNo="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:4L1nuaFrD2r5emcZvcioZshmdOs=
Content-Language: en-US
In-Reply-To: <v6k6ha$1gsq2$4@dont-email.me>
Bytes: 2639

"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes:
....
> To be more precise, printf shall be called if p is 0, NULL or
> nullptr... They are all the same, in a sense, right?

0 and nullptr are null pointer constants. NULL is required to expand
into a null pointer constant, but it's not required to expand into
either 0 or nullptr; it could expand into '\0' or 0ULL or ('a' - 'a'),
among an infinite variety of other possibilities. 0 and (void*)0 are the
two most likely and common choices.

Whenever they occur in a pointer context, null pointer constants get
implicitly converted to the corresponding pointer type, and the result
of that conversion is a null pointer of that type. All null pointers are
required to compare equal. In that sense, 0, NULL and nullptr are all
equivalent.

However, 0 can be used wherever an integer value is required. while
nullptr cannot, which is one of the key reasons for the existence of
nullptr. NULL can expand into an integer constant expression with a
value of 0, but it can also expand into such an expression, converted to
void*. If an implementation chooses the first option, NULL can be used
wherever an integer is allowed. If it chooses the second option, NULL
can only be used where a pointer is allowed.