C++ Logo

std-proposals

Advanced search

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

From: Bo Persson <bo_at_[hidden]>
Date: Mon, 27 Jan 2025 05:34:52 +0100
On 2025-01-27 at 02:34, Gašper Ažman via Std-Proposals wrote:
> You know all pointers are the same size because they're all static_cast-
> able to void* and back.

That only means that pointers are not wider than void*. Some of them
could be smaller.


>
> On Mon, Jan 27, 2025 at 9:12 AM Jeremy Rifkin via Std-Proposals <std-
> proposals_at_[hidden] <mailto:std-proposals_at_[hidden]>> wrote:
>
> > It's possible if the compiler hides it from the programmer. For
> instance if CHAR_BIT==8, and if the CPU instructions deal with 16-
> Bit operands, then you can have:
> >
> > CHAR_BIT == 8
> > sizeof(int*) == 2
> > sizeof(char*) == 3
>
> All the language cares about is that you can in fact address every
> byte of memory. From a language perspective, if CHAR_BIT == 8 then
> the smallest addressable unit of memory is 8 bits irrespective of
> hardware details.
>
> Between https://eel.is/c++draft/basic.memobj#intro.memory-1
> <https://eel.is/c++draft/basic.memobj#intro.memory-1> and https://
> eel.is/c++draft/basic.compound#7 <https://eel.is/c++draft/
> basic.compound#7> and the fact struct Frog; Frog* ptr1 = nullptr;
> Frog* foo(); Frog* ptr2 = foo(); has to work I think it's
> sufficiently covered by the standard that all pointers to non-
> fundamental objects are the same size (or at least compatible in
> some way to make everything here work). Even if you had a system
> where sizeof(char*) == 3 and sizeof(int*) == 2 you would know
> sizeof(void*) >= 3.
>
> Cheers,
> Jeremy
>
>
> On Sun, Jan 26, 2025 at 5:42 PM Frederick Virchanza Gotham via Std-
> Proposals <std-proposals_at_[hidden] <mailto:std-
> proposals_at_[hidden]>> wrote:
>
> On Sun, Jan 26, 2025 at 11:17 PM Jeremy Rifkin wrote:
> >
> > > For example on a system where CHAR_BIT==8 but the smallest
> addressable unit of memory is 16 bits
> >
> > That's not possible https://eel.is/c++draft/
> basic.memobj#intro.memory-1 <https://eel.is/c++draft/
> basic.memobj#intro.memory-1>
>
>
> It's possible if the compiler hides it from the programmer. For
> instance if CHAR_BIT==8, and if the CPU instructions deal with
> 16-Bit
> operands, then you can have:
>
> CHAR_BIT == 8
> sizeof(int*) == 2
> sizeof(char*) == 3
>
> An int* is a 16-Bit number representing a memory address.
> A char* is a 16-Bit number representing a memory address, with an
> extra byte to indicate the offset.

Received on 2025-01-27 04:35:00