Why does Arduino 1.0 beta1 Print treat “signed char”, and “unsigned char” in the new way?
For “signed char”, Print writes the byte as before.
For “unsigned char”, Print converts the byte to its ASCII decimal representation.
This code prints “A” in 0022 but prints “65” in Arduino 1.0 beta.
unsigned char c = 'A'; Serial.println(c);
void print(char); void print(unsigned char, int = DEC);
In the C/C++ standard char can be signed or unsigned so it seems strange to treat them in such a different manner. Why add to the confusion already in C++.
The char type was a problem from the beginning of the C language. Kernighan and Ritchie allowed char to be used as a number but didn’t specify if it was signed or unsigned. They did specify an unsigned char.
After much confusion this was the compromise:
The comprimise was to make signed char a type distinct from the two existing character types, while requiring char to have the same representation and values as either signed char or unsigned char. In other words, a char must look exactly like a signed char or unsigned char to the hardware; which one is implementation-defined. C++ later adopted this compromise for compatibility with C, so both languages now have three distinct char types.