C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Make all data pointers intercompatible

From: Jonathan Wakely <cxx_at_[hidden]>
Date: Tue, 28 Jan 2025 12:47:06 +0000
On Tue, 28 Jan 2025 at 09:42, Frederick Virchanza Gotham via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> Not entirely sure where this thread has ventured off to, but let me
> get back to what I was talking about (i.e. the size of pointers).
> Given the following translation unit:
>
> class MyClass;
> MyClass *my_global_variable;
>
> The compiler doesn't know the alignment requirements of MyClass.


It doesn't need to know them. A pointer to an incomplete type can be
treated as an opaque set of bits, the compiler doesn't need to know how to
interpret those bits because you can't dereference a pointer to an
incomplete type, and you can't create an object of that type. The only
requirement is that it has enough bits to represent any valid address for
objects of that type, which can be determined conservatively. Maybe some
bits will be unused, but that doesn't matter.

But that only tells you that the size of MyClass* needs to be fixed, it
doesn't mean that the representation of MyClass* needs to be the same as
Foo* or Bar*. The bits could have different meanings.

I don't see any benefit from your suggestion to change the rules.

Received on 2025-01-28 12:48:23