|
|
|
|
|
by andreyv
3380 days ago
|
|
std::uint8_t is not required to exist on a particular implementation, for example, if the machine byte is not 8-bit. std::byte still seems pretty useless, though. There already is a built-in type for designating bytes: unsigned char. |
|
(http://open-std.org/JTC1/SC22/WG21/docs/papers/2017/p0298r3....)
Motivation and Scope:
Many programs require byte-oriented access to memory. Today, such programs must use either the char, signed char, or unsigned char types for this purpose. However, these types perform a “triple duty”. Not only are they used for byte addressing, but also as arithmetic types, and as character types. This multiplicity of roles opens the door for programmer error – such as accidentally performing arithmetic on memory that should be treated as a byte value – and confusion for both programmers and tools.
Having a distinct byte type improves type-safety, by distinguishing byte-oriented access to memory from accessing memory as a character or integral value. It improves readability. Having the type would also make the intent of code clearer to readers (as well as tooling for understanding and transforming programs). It increases type-safety by removing ambiguities in expression of programmer’s intent, thereby increasing the accuracy of analysis tools.