C++ Logo

std-proposals

Advanced search

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

From: organicoman <organicoman_at_[hidden]>
Date: Tue, 28 Jan 2025 19:26:37 +0100
>No, not "only". An implementation that e.g. >masks out the least>significant bits of void* on conversion to T*, >according to T's>alignment requirements, is possible. This will violate the strict aliasing rule. And any type can alias any type.>Another implementation that e.g.>modifies tag bits in the pointer according to T >(e.g. to distinguish>between pointed types in hardware to >improve security) is also possible.This is counter intuitive, because you will get a page of unsecured memory with some cells tagged as secured, or the opposite which is worse.Manipulating bits of a pointer should be a programmer responsibility, not the implementation.>Can you point where this is specified in the >standard?In the definition of the pointer type itself as a fundamental type. a pointer as a type defines 5 operations:++ increment , -- decrement , +ptr_diff_t add an offset, * dereference, (T*) castingNone manipulate bits.Sent from my Galaxy
-------- Original message --------From: Andrey Semashev via Std-Proposals <std-proposals_at_[hidden]> Date: 1/28/25 6:58 PM (GMT+01:00) To: Andrey Semashev via Std-Proposals <std-proposals_at_[hidden]> Cc: Andrey Semashev <andrey.semashev_at_[hidden]> Subject: Re: [std-proposals] Make all data pointers intercompatible On 1/28/25 20:51, organicoman wrote:> The following > T* => void* => U* => void* => T* > > Doesn't hold only in one case, when > sizeof(U*) != sizeof(T*),No, not "only". An implementation that e.g. masks out the leastsignificant bits of void* on conversion to T*, according to T'salignment requirements, is possible. Another implementation that e.g.modifies tag bits in the pointer according to T (e.g. to distinguishbetween pointed types in hardware to improve security) is also possible.> Which makes the conversion truncates bytes to fit the value inside the> smaller size.(like from int to short)> But it is always deterministic to guess the final value from the> original value, that is to say , there is no manipulation of individual> bits, especially the lowest ones.Can you point where this is specified in the standard?-- Std-Proposals mailing listStd-Proposals_at_[hidden]://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2025-01-28 18:26:44