Can uint8_t be a non-character type?

后端 未结 4 1757
后悔当初
后悔当初 2020-12-15 22:41

In this answer and the attached comments, Pavel Minaev makes the following argument that, in C, the only types to which uint8_t can be typedef\'d are char

4条回答
  •  一生所求
    2020-12-15 23:28

    In 6.3.1.1 (1) (of the N1570 draft of the C11 standard), we can read

    The rank of any standard integer type shall be greater than the rank of any extended integer type with the same width.

    So the standard explicitly allows the presence of extended integer types of the same width as a standard integer type.

    There is nothing in the standard prohibiting a

    typedef implementation_defined_extended_8_bit-unsigned_integer_type uint8_t;
    

    if that extended integer type matches the specifications for uint8_t (no padding bits, width of 8 bits), as far as I can see.

    So yes, if the implementation provides such an extended integer type, uint8_t may be typedef'ed to that.

提交回复
热议问题