Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The C standard uses the general philosophy outlined below for choosing character types, though it is not explicitly stated in one place.

signed char and unsigned char

  • Suitable for small integer values

"plain" char

  • The type of each element of a string literal.
  • Used for character data (where signedness has little meaning) as opposed to integer data.

int

  • Used for data that could be either EOF (a negative value) or character data interpreted as unsigned char and then converted to int.  Therefore, returned by fgetc(), getc(), getchar(), and ungetc().  Also, accepted by the character handling functions from <ctype.h>, because they might be passed the result of fgetc() et al.
  • The type of a character constant.  Its value is that of a plain char converted to int.

unsigned char

  • Used internally for string comparison functions, even though these operate on character data.  Therefore, 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().

...

Wiki Markup
\[[ISO/IEC TR 24731-1-2007|AA. C References#ISO/IEC TR 24731-1-2007]\]
\[[ISO/IEC 9899-1999|AA. C References#ISO/IEC 9899-1999]\] Section 7.1.1, "Definitions of terms," and Section 7.21, "String handling <string.h>"
\[[Seacord 05a|AA. C References#Seacord 05a]\] Chapter 2, "Strings"
\[[Seacord 05b|AA. C References#Seacord 05b]\]

...