can I assume that sizeof(uint8_t) = 1?

Tom picture Tom · Feb 7, 2018 · Viewed 8.3k times · Source

I have a program that uses dynamic allocation for a uint8_t array; can I safely assume that its length will always be one byte?

Answer

If uint8_t exists, then sizeof(uint8_t) must be 1. uint8_t is required to have width exactly 8 and no padding bits, and CHAR_BIT is required to be at least 8. If uint8_t exists, it can't have more than one char's worth of bits without violating these requirements.