C++ Logo

std-proposals

Advanced search

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

From: Andrey Semashev <andrey.semashev_at_[hidden]>
Date: Fri, 25 Jul 2025 18:49:35 +0300
On July 25, 2025 3:19:58 PM Frederick Virchanza Gotham via Std-Proposals
<std-proposals_at_[hidden]> wrote:

> On Fri, Jul 25, 2025 at 1:03 PM Andrey Semashev wrote:
>>
>> There is only one pointer value that is guaranteed to not point at any
>> object, and that's nullptr. If you want to add another one, that would
>> have to go beyond just defining a new constant. The whole runtime
>> (including but not limited to the memory allocator) would have to be
>> updated with support for this new constant.
>
>
> Not really. There isn't a computer in existence today -- I don't think
> -- that uses more than 49 bits for a memory address. 64-Bit ARM uses
> 48 bits but it can be extended by 1 bit to 49 bits.
>
> So you can mark a pointer as 'bad' by manipulating the top 15 bits. Or
> even just set the top bit high.

Those bits are already utilized e.g. for pointer tagging. And this sort of
things is beyond C++ standard domain anyways. A system that has a different
memory layout than what you're used to should still be possible to support.

>

Received on 2025-07-25 15:49:40