Search code examples
csizeofuint8tuint

can I assume that sizeof(uint8_t) = 1?


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?


Solution

  • 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.