...
Note that the two different ways a character is used as an int
(as an unsigned char
+ EOF
, or as a plain char
, converted to int
) can lead to confusion. For example, isspace('\200')
results in undefined behavior when char
is signed.
unsigned char
Unlike other integer types, unsigned char
has the unique property that (quoting from Section 6.2.6.1 of C99):
Wiki Markup Values stored in \[...\] objects of type unsigned char shall be represented using a pure binary notation.
where a pure binary notation is defined as
A positional representation for integers that uses the binary digits 0 and 1, in which the values represented by successive bits are additive, begin with 1, and are multiplied by successive integral powers of 2, except perhaps the bit with the highest position. A byte contains
CHAR_BIT
bits, and the values of typeunsigned char
range from 0 to 2CHAR_BIT
- 1 .
That is, objects of type unsigned char
may have no padding bits and thus no trap representation. Thus, non-bit field objects of any type may be copied into an array of unsigned char
(e.g., via memcpy()
) and have their representation examined one byte at a time.
- Used internally for string comparison functions, even though these operate on character data. Consequently, the result of a string comparison does not depend on whether plain
char
is signed. - Used for situations where the object being manipulated might be of any type, and it is necessary to access all bits of that object, as with
fwrite()
.
...