Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Underlying type for std::uint8_t

Question:
Is there any c++ toolchain, where std::uint8_t exists, but is not a typedef for unsigned char (or char, if it is unsigned)?

EDIT: Conversely: Is such a thing even possible in a standards conforming implementation?

Background / Motivation:
I'm mainly asking because I want to know if std::uint8_t* can be used portably to access individual bytes (just like unsigned char*). And yes, I'm aware of std::byte, but thats not relevant here. I'm mainly interested in toolchains for x86, arm and mips, but out of curiosity I'd also like to hear about other examples.

like image 445
MikeMB Avatar asked Jun 21 '17 20:06

MikeMB


1 Answers

  1. char is not an unsigned integer type, even if it is, in fact, unsigned. Since uint8_t must be a unsigned integer type, it never can be char.
  2. CHAR_BIT must be at least 8, while the next smallest standard unsigned integer type, unsigned short, must have at least 16 bits. If uint8_t exists, then it must be "an unsigned integer type with width 8 and no padding bits." If uint8_t denotes a standard unsigned integer type, then it can only be unsigned char.
  3. However, nothing in the wording prevents uint8_t from denoting an implementation-defined extended unsigned integer type. I don't know of any implementations that do this, however.
like image 157
T.C. Avatar answered Nov 02 '22 23:11

T.C.