C++ Logo

std-discussion

Advanced search

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

From: Roman Babinicz <rb_at_[hidden]>
Date: Wed, 5 Aug 2020 07:57:43 +0200
enum class mybyte : unsigned char{};
using T1 = mybyte;
auto ptr = new T1 [100];
*(ptr+10) = static_cast<T1>(50);
delete []ptr;

Is this well formed way of accessing object via glvalue pointer
(as in basic.lval#11.3) ?

Because for some other types T1, e.g. for int, one possible reading of
standard is that this is UB and you need to memcpy the buffer into a new
location first (and even more likelly needed for non-fundamental types
in T1).

Received on 2020-08-05 01:01:09