Date: Mon, 27 Jan 2025 16:42:00 +0900
I think it can change representation but not size
On Mon, Jan 27, 2025, 16:36 Sebastian Wittmeier via Std-Proposals <
std-proposals_at_[hidden]> wrote:
> Is there a guarantee that a cast of a pointer does not change its
> representation and size?
>
>
> -----Ursprüngliche Nachricht-----
> *Von:* Gašper Ažman via Std-Proposals <std-proposals_at_[hidden]>
> *Gesendet:* Mo 27.01.2025 02:34
> *Betreff:* Re: [std-proposals] Make all data pointers intercompatible
> *An:* std-proposals_at_[hidden];
> *CC:* Gašper Ažman <gasper.azman_at_[hidden]>;
> You know all pointers are the same size because they're all
> static_cast-able to void* and back.
>
> On Mon, Jan 27, 2025 at 9:12 AM Jeremy Rifkin via Std-Proposals <
> 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 and
> 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]> 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
>
>
> 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.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
On Mon, Jan 27, 2025, 16:36 Sebastian Wittmeier via Std-Proposals <
std-proposals_at_[hidden]> wrote:
> Is there a guarantee that a cast of a pointer does not change its
> representation and size?
>
>
> -----Ursprüngliche Nachricht-----
> *Von:* Gašper Ažman via Std-Proposals <std-proposals_at_[hidden]>
> *Gesendet:* Mo 27.01.2025 02:34
> *Betreff:* Re: [std-proposals] Make all data pointers intercompatible
> *An:* std-proposals_at_[hidden];
> *CC:* Gašper Ažman <gasper.azman_at_[hidden]>;
> You know all pointers are the same size because they're all
> static_cast-able to void* and back.
>
> On Mon, Jan 27, 2025 at 9:12 AM Jeremy Rifkin via Std-Proposals <
> 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 and
> 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]> 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
>
>
> 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.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
Received on 2025-01-27 07:42:14