Date: Mon, 27 Jan 2025 09:06:13 +0000
I think the question here is, is there anything that can be done about it?
I suspect that the number of systems where the smallest addressable unit is 16bit to be quite rare.
I would expect from a theoretical stand point that in such systems a char would have 16bits instead of 8.
In practice the reason why they are 16bits is because it's the only available register size, and as such the memory that they would have available would be very limited. In those systems you would still want a char to be 8 bit, and you would store 2chars in 1 memory unit in order to save the limited memory you have.
Given the memory limitation of such a system, you probably don't have much of an operating system to run on, and probably a lot of the standard components wouldn't quite fit anyways so you are not looking at a system that could be fully standard compliant anyways.
The point here being that if a system has this weird behavior, it does so for a reason, and because of that reason there really isn't much you can do about it. Whatever limited ABI it might have, you wouldn't want to change how those pointers work, regardless of the standard might say.
Systems that can afford to be standard compliant won't have this problem.
So, it seems that any change in this area would either be met with either “it makes no difference in my system” (so nothing changes) or “I’ve a reason not to do this, so… well I guess this is just going to be another way in which my system is going to be incompatible with the standard” (and nothing changes).
And after all had been done, nothing in practice would have changed.
So what is the point of this?
________________________________
From: Std-Proposals <std-proposals-bounces_at_[hidden]> on behalf of Gašper Ažman via Std-Proposals <std-proposals_at_[hidden]>
Sent: Monday, January 27, 2025 8:42:25 AM
To: std-proposals_at_[hidden] <std-proposals_at_[hidden]>
Cc: Gašper Ažman <gasper.azman_at_[hidden].com>
Subject: Re: [std-proposals] Make all data pointers intercompatible
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]<mailto: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]<mailto: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]<mailto:std-proposals_at_[hidden]>;
CC: Gašper Ažman <gasper.azman_at_[hidden]<mailto: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]<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 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]<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
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_lists.isocpp.org<mailto:Std-Proposals_at_[hidden]>
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
--
Std-Proposals mailing list
Std-Proposals_at_[hidden]<mailto:Std-Proposals_at_[hidden]>
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
--
Std-Proposals mailing list
Std-Proposals_at_[hidden]<mailto:Std-Proposals_at_[hidden]>
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
--
Std-Proposals mailing list
Std-Proposals_at_[hidden]<mailto:Std-Proposals_at_[hidden]>
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
I suspect that the number of systems where the smallest addressable unit is 16bit to be quite rare.
I would expect from a theoretical stand point that in such systems a char would have 16bits instead of 8.
In practice the reason why they are 16bits is because it's the only available register size, and as such the memory that they would have available would be very limited. In those systems you would still want a char to be 8 bit, and you would store 2chars in 1 memory unit in order to save the limited memory you have.
Given the memory limitation of such a system, you probably don't have much of an operating system to run on, and probably a lot of the standard components wouldn't quite fit anyways so you are not looking at a system that could be fully standard compliant anyways.
The point here being that if a system has this weird behavior, it does so for a reason, and because of that reason there really isn't much you can do about it. Whatever limited ABI it might have, you wouldn't want to change how those pointers work, regardless of the standard might say.
Systems that can afford to be standard compliant won't have this problem.
So, it seems that any change in this area would either be met with either “it makes no difference in my system” (so nothing changes) or “I’ve a reason not to do this, so… well I guess this is just going to be another way in which my system is going to be incompatible with the standard” (and nothing changes).
And after all had been done, nothing in practice would have changed.
So what is the point of this?
________________________________
From: Std-Proposals <std-proposals-bounces_at_[hidden]> on behalf of Gašper Ažman via Std-Proposals <std-proposals_at_[hidden]>
Sent: Monday, January 27, 2025 8:42:25 AM
To: std-proposals_at_[hidden] <std-proposals_at_[hidden]>
Cc: Gašper Ažman <gasper.azman_at_[hidden].com>
Subject: Re: [std-proposals] Make all data pointers intercompatible
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]<mailto: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]<mailto: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]<mailto:std-proposals_at_[hidden]>;
CC: Gašper Ažman <gasper.azman_at_[hidden]<mailto: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]<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 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]<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
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_lists.isocpp.org<mailto:Std-Proposals_at_[hidden]>
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
--
Std-Proposals mailing list
Std-Proposals_at_[hidden]<mailto:Std-Proposals_at_[hidden]>
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
--
Std-Proposals mailing list
Std-Proposals_at_[hidden]<mailto:Std-Proposals_at_[hidden]>
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
--
Std-Proposals mailing list
Std-Proposals_at_[hidden]<mailto:Std-Proposals_at_[hidden]>
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
Received on 2025-01-27 09:06:20