Follow

@cafou

"char" is a signed type - it runs negative as well as positive, and thus (for example) can hold the value -32 but can't hold the value 192 (assuming your system uses eight-bit characters). You can get around that by making sure to use "unsigned char" - but at this point I should draw your attention again to that earlier parenthesis.

"unsigned char" is _usually_ eight bits of unsigned data, which can be used for byte manipulations. But there is _no_guarantee that this will still hold in future compilers - or even in different locale settings (unicode characters come from a list that is _way_ longer than the 256-character ASCII set, and it's always possible that, one day, compilers will default to a unicode char type...)

On the other hand, if you use uint8_t, then you are _specifically_ calling for an unsigned eight-bit integer - and if you're doing byte manipulations, then that's what you want. Right now, it'll be exactly the same as the unsigned char... but in twenty years, there may very well be a future programmer complaining about all the code using these huge 16-bit characters because it causes all _sorts_ of issues for byte manipulation!

Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.