C++ Logo

std-proposals

Advanced search

Re: Allowing access to object representations

From: language.lawyer_at <language.lawyer_at_[hidden]>
Date: Thu, 22 Aug 2019 04:58:15 +0300
On 22/08/2019 04:29, Barry Revzin via Std-Proposals wrote:
> On Wed, Aug 21, 2019 at 6:38 PM sdkrystian via Std-Proposals <std-proposals_at_[hidden] <mailto:std-proposals_at_[hidden]>> wrote:
>
> > It's nothing to do with the value of the int object as a whole, but of the leftmost byte. Why on earth would it /not/ depend on endianness?
>
> Because the standard says so. Here are some citations:
>
> In that particular cast, the value of the pointer is unchanged. http://eel.is/c++draft/expr.static.cast#13.sentence-4
>
> Since the value is unchanged, it still points to the int object. Therefore, when the indirection operator is used, it yields an lvalue of type `char` that denotes the object the pointer points to. http://eel.is/c++draft/expr.unary.op#1.sentence-1
>
>
> This part is fine.
>
>
> Now, when an lvalue-to-rvalue conversion is applied to the lvalue (such as during initialization), the result is the value of the object (which has NOT been truncated), and since that value is within the representable range of `char`, the behavior is well defined, and will ALWAYS yield 42.
>
>
> This part does not follow.

It does, from http://eel.is/c++draft/conv.lval#3.4

Received on 2019-08-21 21:00:21