If the hardware supports 8-bit integers with no padding, then std::uint8_t will be defined, and could be used for that purpose.
enum class octet : std::uint8_t {};
// add bitwise ops similar to the operator overloads for std::byte
// alternatively, use std::uint8_t directly
However, this is basically pointless. If unsigned char is wider than 8 bits, then std::uint8_t won't be defined because no type can be smaller than a byte in C++.
Any "true octet" type is either not going to be portable, or it will require padding. If padding is acceptable, you can define it as follows:
Also, as commenters have pointed out, hardware with no support for 8-bit types is extremely rare. Unless you expect to compile your code for digital signal processors (DSPs) or other unusual hardware, just assume 8-bit bytes. Use std::uint8_t, or
If the hardware supports 8-bit integers with no padding, then
std::uint8_twill be defined, and could be used for that purpose.However, this is basically pointless. If
unsigned charis wider than 8 bits, thenstd::uint8_twon't be defined because no type can be smaller than a byte in C++.Any "true octet" type is either not going to be portable, or it will require padding. If padding is acceptable, you can define it as follows:
Also, as commenters have pointed out, hardware with no support for 8-bit types is extremely rare. Unless you expect to compile your code for digital signal processors (DSPs) or other unusual hardware, just assume 8-bit bytes. Use
std::uint8_t, or