C++ Logo

STD-DISCUSSION

Advanced search

Subject: Re: reading values as bytes without memcpu, from enum unsigned char?
From: language.lawyer_at_[hidden]
Date: 2020-08-07 09:06:38


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.


STD-DISCUSSION list run by std-discussion-owner@lists.isocpp.org

Older Archives on Google Groups