C++ Logo

std-proposals

Advanced search

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

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Fri, 25 Jul 2025 12:33:21 +0100
On Fri, Jul 25, 2025 at 12:24 PM Jarrad Waterloo wrote:
>
> Frederick,
>
> I know that references can't be EXPLICITLY set to nullptr.
> Could something like this be used to say that INTERNALLY
> references are set to nullptr or 0xdeadbeef, even in production,
> to ensure that we get a segfault if the memory hasn't been overwritten?


I think you're saying that an alteration would be made to the
compiler, so that if it ever encounters a reference, and if the
reference internally refers to an object located at 0xdeadbeef, then
the compiler (not the debugger) will put code inside the binary that
kills the program and explains what went wrong?

Actually I'm not totally sure what you're saying . . . maybe you're
talking about the point at which the reference is created, so for
example when the compiler sees the following when NDEBUG is not
defined:

    MyClass &ref = *(MyClass*)badptr;

It emits code that checks if the referred object lives at 0xdeadbeef,
and if so, it kills the program and gives an explanation?

Compilers, when building debug binaries, could emit extra code to
always be checking for 0xdeadbeef.

Received on 2025-07-25 11:33:33