Date: Tue, 28 Jan 2025 12:13:08 +0000
On Tue, Jan 28, 2025 at 11:49 AM Jens Maurer wrote:
>
> I still don't understand what exactly you mean by "intercompatible".
Here's what I want:
Point 1) void* and char* are exactly the same.
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. Same representation too, obviously.
Point 3) No loss of precision when converting between pointer types
whose pointed-to type have differing alignment requirements.
Specifically:
Even though the memory address of a 'double' will always be a multiple
of 8, I want the lower 3 bits of the pointer to still retain their
value, so that the following is possible:
Line 1: char c;
Line 2: double *p = static_cast<double*>(static_cast<void*>(&c));
Line 3: char *p2 = static_cast<char*>(static_cast<void*>( p ));
Line 4: *p2 = 'h';
Looking at Line #2, I could see that a compiler could possibly
zero-out the lower 3 bits of the value of 'p', but I want this to be
forbidden in C++26.
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).
>
> I still don't understand what exactly you mean by "intercompatible".
Here's what I want:
Point 1) void* and char* are exactly the same.
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. Same representation too, obviously.
Point 3) No loss of precision when converting between pointer types
whose pointed-to type have differing alignment requirements.
Specifically:
Even though the memory address of a 'double' will always be a multiple
of 8, I want the lower 3 bits of the pointer to still retain their
value, so that the following is possible:
Line 1: char c;
Line 2: double *p = static_cast<double*>(static_cast<void*>(&c));
Line 3: char *p2 = static_cast<char*>(static_cast<void*>( p ));
Line 4: *p2 = 'h';
Looking at Line #2, I could see that a compiler could possibly
zero-out the lower 3 bits of the value of 'p', but I want this to be
forbidden in C++26.
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).
Received on 2025-01-28 12:13:25