In Kernighan & Ritchie, it says that “all printable characters are positive when though char datatype being signed or unsigned is machine-dependent.”
Can somebody explain to me the meaning of this line ? My system has signed chars but even with a negative value say of -90, printf does print a character (even though its not a very familiar character).
ASCII character set defines codepoints from
0x00to0x7F. It doesn’t matter if they are represented with unsigned or signed byte values since this range is common for both.Printable characters are between
0x20and0x7E, which are all part of the ASCII. The term printable character does not define every possible character in the world that is printable. Rather it is defined inside the realm of ASCII.Byte values from
0x80to0xFFare not defined in ASCII and different systems assign different characters to values in this range resulting in many different types of codepages which are identical in their ASCII range but differ in this range. This is also the range where values for signed and unsigned bytes differ.The implementation of
printflooks for a single byte value when it encounters a%ckey in its input. This byte value may be signed or unsigned with respect to your point of view as the caller ofprintffunction butprintfdoes not know this. It just passes these 8bits to the output stream it’s connected to and that stream emits characters within0x00and0xff.The concept of sign has no meaning inside the output pipeline where characters are emitted. Thus, whether you send a
255or a-1, the character mapped to0xFFin the specific codepage is emitted.