Reading Herb Sutter's blog post about the most recent C++ standard meeting, it noticed that std::byte
was added to C++17. As an initial reading, I have some concerns since it uses unsigned char
so that it can avoid complications with strict aliasing rules.
My biggest concern is, how does it work on platforms where CHAR_BIT
is not 8? I have worked on/with platforms where CHAR_BIT
is 16 or 32 (generally DSPs). Given that std::byte
is for dealing with "byte-oriented access to memory", and most people understand byte to indicate an octet (not the size of the underlying character type), how will this work for individuals who expect that this will address contiguous 8-bit chunks of memory?
I already see people who just assume that CHAR_BIT
is 8 (not evening knowing that CHAR_BIT
exists...). A type called std::byte
is likely to introduce even more confusion to individuals.
I guess that what I expected was that they were introducing a type to permit consistent addressing/access to sequential octets for all cases. There are many octet-oriented protocols where it would be useful to have a library or type that is guaranteed to access memory one octet at a time on all platforms, no matter what CHAR_BIT
is equal to on the given platform.
I can definitely understand wanting to have it well specified that something is being used as a sequence of bytes rather than a sequence of characters, but it doesn't seem like being as useful as many other things might be.