简体   繁体   中英

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.

  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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM