C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Standardising 0xdeadbeef for pointers

From: Jonathan Wakely <cxx_at_[hidden]>
Date: Fri, 25 Jul 2025 21:53:40 +0200
On Fri, 25 Jul 2025, 19:32 Frederick Virchanza Gotham via Std-Proposals, <
std-proposals_at_[hidden]> wrote:

>
>
> On Friday, July 25, 2025, Julien Villemure-Fréchette wrote:
>
>>
>> Even the following is unspecified (could be true or false)
>> "(void*)nullptr != reinterpret_cast<void*>(0x0)"
>>
>
>
>
> I think you're suggesting it might be false if a nullptr is represented in
> memory by all bits 1.
>
> Which has never happened. Never ever.
>
> I'm not even talking just about C and C++. No programming language has
> ever represented a null pointer with anything other than all bits zero.
>
> That's why I 'memset(p,0,sizeof p)' for arrays of pointers.
>

Do you think compilers are not smart enough to do that if you just
initialize the array with {} or is there some other reason?

"I know null pointers are all zero bits" is not a very good reason, even if
it's true on all your platforms. Because if it's true, the compiler knows
it too, and is quite capable of using memset for the initialization if
that's optimal.

Received on 2025-07-25 19:53:58