Using unsigned char
"always" could give you some interesting surprises, as the majority of C-style functions like printf
, fopen
, will use char
, not unsigned char
.
edit: Example of "fun" with C-style functions:
const unsigned char *cmd = "grep -r blah *.txt";
FILE *pf = popen(cmd, "r");
will give errors (in fact, I get one for the *cmd =
line, and one error for the popen
line). Using const char *cmd = ...
will work fine. I picked popen
because it's a function that isn't trivial to replace with some standard C++ functionality - obviously, printf
or fopen
can quite easily be replaced with some iostream
or fstream
type functionality, which generally has alternatives that take unsigned char
as well as char
.
However, if you are using >
or <
on characters that are beyond 127, then you will need to use unsigned char
(or some other solution, such as casting to int
and masking the lower 8 bits). It is probably better to try to avoid direct comparisons (in particular when it comes to non-ASCII characters - they are messy anyway, because there are often several variants depending on locale, character encodings, etc). Comparing for equality should work however.