When storing “byte arrays” (blobs…) is it better to use char or unsigned char for the items (unsigned char a.k.a. uint8_t)? (Standard says that sizeof of both is precisely 1 Byte.)
Does it matter at all? Or one is more convenient or prevalent than the other? Maybe, what libraries like Boost do use?
If
charis signed, then performing arithmetic on a byte value with the high bit set will result in sign extension when promoting toint; so, for example:will give
0xfffffff0instead of0xf0f0f0f0. This can be avoided by masking with0xff.charmay still be preferable if you’re interfacing with libraries that use it instead ofunsigned char.Note that a cast from
char *to/fromunsigned char *is always safe (3.9p2). A philosophical reason to favourunsigned charis that 3.9p4 in the standard favours it, at least for representing byte arrays that could hold memory representations of objects: