Date: Tue, 28 Jan 2025 17:10:52 +0100
Although i don't see any data to prevent that from being standard, but i guess we need to consult more third party to get the final word.Especially OS makers since they implement:std::malloc, which is the source of size and alignment of most pointers.Sent from my Galaxy
-------- Original message --------From: Frederick Virchanza Gotham via Std-Proposals <std-proposals_at_[hidden]> Date: 1/28/25 4:29 PM (GMT+01:00) To: std-proposals_at_[hidden] Cc: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]> Subject: Re: [std-proposals] Make all data pointers intercompatible On Tue, Jan 28, 2025 at 3:16 PM organicoman wrote:>> The resulting pointer is unspecified: means dereferencing it is UB.> Because the compiler is not allowed to alter the bits of A. It will keep it as given.>> I can do the following.>> double* ptr = reinterpret_cast<double*>(0x7fff934a9d83); // misaligned for double>> ptr value will stay 0x7fff934a9d83, but it is unusable otherwise:> *ptr is UB> ++ptr is UB> --ptr is UB> ptr+int the result is UB.> ...etcI want the C++26 Standard to say that the implementation shall havepointers into data memory, and that the size of these pointers shallbe implementation-defined (e.g. 32-Bit or 64-Bit).All data pointer types are exactly the same (same size, samealignment, same representation).Data pointer arithmetic is well-defined for all data pointer types,even if the pointer contains a value which is misaligned. So if wehave a pointer to a misaligned double: double *ptr = reinterpret_cast<double*>(0x7fff934a9d83);Then I want "++ptr" to add 8 to it, giving 0x7FFF934A9D8B. I want thisto be well-defined behaviour.Of course though, to dereference it would still be UB.By the way . . . . . just in case anyone's wondering . . . . . whatI'm asking for is already possible with all modern C++ compilers, Ijust want it to be written in stone in the Standard.-- Std-Proposals mailing listStd-Proposals_at_[hidden]://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
-------- Original message --------From: Frederick Virchanza Gotham via Std-Proposals <std-proposals_at_[hidden]> Date: 1/28/25 4:29 PM (GMT+01:00) To: std-proposals_at_[hidden] Cc: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]> Subject: Re: [std-proposals] Make all data pointers intercompatible On Tue, Jan 28, 2025 at 3:16 PM organicoman wrote:>> The resulting pointer is unspecified: means dereferencing it is UB.> Because the compiler is not allowed to alter the bits of A. It will keep it as given.>> I can do the following.>> double* ptr = reinterpret_cast<double*>(0x7fff934a9d83); // misaligned for double>> ptr value will stay 0x7fff934a9d83, but it is unusable otherwise:> *ptr is UB> ++ptr is UB> --ptr is UB> ptr+int the result is UB.> ...etcI want the C++26 Standard to say that the implementation shall havepointers into data memory, and that the size of these pointers shallbe implementation-defined (e.g. 32-Bit or 64-Bit).All data pointer types are exactly the same (same size, samealignment, same representation).Data pointer arithmetic is well-defined for all data pointer types,even if the pointer contains a value which is misaligned. So if wehave a pointer to a misaligned double: double *ptr = reinterpret_cast<double*>(0x7fff934a9d83);Then I want "++ptr" to add 8 to it, giving 0x7FFF934A9D8B. I want thisto be well-defined behaviour.Of course though, to dereference it would still be UB.By the way . . . . . just in case anyone's wondering . . . . . whatI'm asking for is already possible with all modern C++ compilers, Ijust want it to be written in stone in the Standard.-- Std-Proposals mailing listStd-Proposals_at_[hidden]://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
Received on 2025-01-28 16:10:58