C++ Logo

STD-PROPOSALS

Advanced search

Subject: Re: [std-proposals] Allowing access to object representations
From: Jake Arkinstall (jake.arkinstall_at_[hidden])
Date: 2019-08-21 19:16:24


On Thu, 22 Aug 2019, 00:38 sdkrystian via Std-Proposals, <
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.
>

It does. But the char pointer points to the first byte. Which is platform
dependant.

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
>

Which is a char. At this point, the source object being an int is not
relevant (or known, in the case of static compiled libraries that expect a
char). Otherwise reinterpret cast is completely redundant for any practical
uses.

>



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

Standard Proposals Archives on Google Groups