In C++ (and C too), char as is should be used to represent the ASCII characters, and the reason one wishes to use the unsigned char and signed char is if the purpose is to use small integral types (-128 to 127 and 0 - 255 range, respectively where a char is ~ 1B).
So trivial code below, is why doesn't it output an integer but that I needed to typecast it, but doesn't this defeat purpose of trying to use a small int since a short is ~ 2B, so what's the benefit of unsigned/signed char then?
Code:
int main()
{
unsigned char x = 65;//what is this for, if it doesn't print a small int (1B) but 'A' instead
cout << short(x) << endl;//If I have to typecast it, the short (smallest integer type) than it's going to take up 2B so defeats purpose of using a small int for whatever reason...
return 0;
}
And we should use int8_t and uint8_t to avoid ambiguity for portability, just as we should use size_t, time_t, is that correct? But my question is not this, but why we need to typecast to output its integer value since a short (smallest integer type of 2B) needs to be used but a char is only 1B so we don't save space to use a char to represent small integers. I hope I am clear what I mean...