>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*) casting
None manipulate bits.
-------- Original message --------
From: Andrey Semashev via Std-Proposals <std-proposals@lists.isocpp.org>
Date: 1/28/25 6:58 PM (GMT+01:00)
To: Andrey Semashev via Std-Proposals <std-proposals@lists.isocpp.org>
Cc: Andrey Semashev <andrey.semashev@gmail.com>
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 least
significant bits of void* on conversion to T*, according to T's
alignment requirements, is possible. 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.
> 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 list
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals