C++ Logo

STD-DISCUSSION

Advanced search

Subject: reading values as bytes without memcpu, from enum unsigned char?
From: Roman Babinicz (rb_at_[hidden])
Date: 2020-08-05 00:57:43


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).


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

Older Archives on Google Groups