C++ Logo

std-proposals

Advanced search

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

From: Thiago Macieira <thiago_at_[hidden]>
Date: Tue, 28 Jan 2025 09:43:18 -0800
On Tuesday 28 January 2025 04:13:08 Pacific Standard Time Frederick Virchanza
Gotham via Std-Proposals wrote:
> Point 1) void* and char* are exactly the same.

I am asserting this is already the case by corollary.

> Point 2) All data pointers have the same size and alignment. So if you
> apply "sizeof" or "alignof" to any data pointer, you always get the
> same answer.

That's effectively the case and I think we *could* require this, but I don't
see the benefit.

> Same representation too, obviously.

No on this one. Representation is entirely internally-dependent and shouldn't
be mandated.

> Point 3) No loss of precision when converting between pointer types
> whose pointed-to type have differing alignment requirements.

No on this one either.

> This would be a major simplification of data pointers in C++, and it
> would aid in relocating objects into unaligned memory (for example
> std::basic_string<char32_t> which contains a pointer pointing into its
> own internal buffer).

You need to know if your machine supports unaligned access in the first place.
That's system-dependent and you're beyond the standard. If you know that your
machine does support it, you can use this information for your own code.

If you don't know it, you cannot manipulate unaligned objects. The Standard
says that's not defined behaviour and that is not going to change. That being
the case, there's no point in having a pointer support misaligned content.



-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel DCAI Platform & System Engineering

Received on 2025-01-28 17:43:22