in some code seen online, i saw that in read function in C, someone uses a uint8_t array for buffer insted of a char array buffer. what are the differences? thanks
CodePudding user response:
The C standard allows char
to be signed or unsigned. It also allows it to be more than eight bits.
uint8_t
, if it is defined, is unsigned and eight bits. This allows programmers to be completely sure of the type that will be used. In particular, signed char
types sometimes cause problems with bitwise and shift operations, due to how these operations are defined (or are not defined) when negative values are involved.
CodePudding user response:
So every char corresponds to a number(see ascii table here). I think people use this to avoid some problems(sorry I don't use c I come from c )