Deutsch   English   Français   Italiano  
<87frsmsznj.fsf@nosuchdomain.example.com>

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

Path: ...!2.eu.feeder.erje.net!feeder.erje.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: question about nullptr
Date: Sat, 06 Jul 2024 19:29:20 -0700
Organization: None to speak of
Lines: 38
Message-ID: <87frsmsznj.fsf@nosuchdomain.example.com>
References: <v6bavg$3pu5i$1@dont-email.me> <20240706054641.175@kylheku.com>
	<v6bfi1$3qn4u$1@dont-email.me> <l9ciO.7$cr5e.2@fx05.iad>
	<v6c942$3ui41$1@dont-email.me> <v6crt3$1gpa$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 07 Jul 2024 04:29:22 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="31bef4326a7de5d231f958bc2ab73da5";
	logging-data="192035"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18llEsHiFxYzRCXC0+3XTnj"
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:/3/f3ECrKG+hGpYYbofKMWbTR78=
	sha1:3741CFAqVzZWwyFibp5UwHls3LA=
Bytes: 2765

James Kuyper <jameskuyper@alumni.caltech.edu> writes:
> On 7/6/24 4:23 PM, Chris M. Thomasson wrote:
>> On 7/6/2024 7:04 AM, Scott Lurndal wrote:
> ...
>>> Whereas I spent 6 years programming on an architecture[*] where a
>>> null pointer was represented in hardware by the value 0xc0eeeeee.  I 
>>> always
>>> use the NULL macro in both C and C++ code.
>> 
>> Where:
>> 
>> void* x = 0;
>> 
>> Should be x = 0xc0eeeeee, right?
>
> No, 0 is a null pointer constant. The C standard requires that when a
> null pointer constant is converted to a pointer value, it must be
> converted to a null pointer of that type. The result will be that the
> representation of 'x' after such an assignment would be 0xc0eeeeee.
>
> Whether or not an integer value of 0xc0eeeeee can be converted to a
> pointer type, and what that pointer's value would be after the
> conversion is up to the implementation.
>
> Note that even after x acquires that representation, it's still required
> to compare equal to 0. For the purposes of the comparison, the null
> pointer constant gets converted to a null pointer of the appropriate
> type. All null pointers, regardless of representation (the C standard
> allows there to be multiple ways of representing null pointers) must
> compare equal.

Furthermore, `void* x = 0xc0eeeeee;` is a constraint violation.  There
is no implicit conversion from integers to pointers other than the
special case of a null pointer constant, which 0xc0eeeeee is not.

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */