C++ Logo


Advanced search

Subject: Re: [std-proposals] Allowing access to object representations
From: language.lawyer_at_[hidden]
Date: 2019-08-21 13:16:03

By "dereferencing" you mean "applying indirection operator to reinterpret_cast<...>" or lvalue-to-rvalue conversion applied to this indirection?
`*reinterpret_cast<char*>(&some_object)` generally is an lvalue of `char` type denoting `some_object`, with some exceptions like: `some_object` is a standard-layout struct which has the first non-static data member of `char` type etc.

On 21/08/2019 21:09, Timur Doumler wrote:
> Ok, so what is then, formally, the semantics of dereferencing a reinterpret_cast<char*>(&some_object); and is this defined behaviour?
> Cheers,
> Timur
>> On 21 Aug 2019, at 20:05, 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

STD-PROPOSALS list run by herb.sutter at gmail.com

Standard Proposals Archives on Google Groups