C++ Logo


Advanced search

Re: reading values as bytes without memcpu, from enum unsigned char?

From: language.lawyer_at <language.lawyer_at_[hidden]>
Date: Fri, 7 Aug 2020 17:06:38 +0300
On 07/08/2020 16:51, Jason McKesson via Std-Discussion wrote:
> The cast is legal. Accessing the `unsigned char` at that address is
> legal.

You can't access `unsigned char` objects, `reinterpret_cast<unsigned char*>(buf)` points to the object of `mybyte` type.
But accessing an object of `mybyte` type through a glvalue of `unsigned char` type is indeed legal, because an enumeration with a fixed underlying type has the same values as the underlying type.

Received on 2020-08-07 09:10:06