C++ Logo

std-proposals

Advanced search

Re: Allowing access to object representations

From: Krystian Stasiowski <sdkrystian_at_[hidden]>
Date: Wed, 21 Aug 2019 14:44:07 -0400
Yes, you can. If the pointer value is unchanged, then it still points to
the original object, and since the resulting pointer is of, say, char,
unsigned char, or std::byte, the strict aliasing rules allow you to access
the object.

On Wed, Aug 21, 2019 at 2:05 PM language.lawyer--- via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> On 21/08/2019 11:22, sdkrystian via Std-Proposals wrote:
> > Using reinterpret_cast, you can access the first element, but thats
> about it (pointer arithmetic is UB)
>
> No, u can't access "the first element".
> reinterpret_cast won't change the pointer value, the result of
> reinterpret_cast "points to" the same object to which the argument of
> reinterpret_cast pointed to.
> Indirection through such a pointer yields an lvalue denoting the object to
> which pointer points to and this influences lvalue-to-rvalue conversion
> applied to (or assignment through) this lvalue in a funny way.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2019-08-21 13:46:25