Versions Compared

Key

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

The three types char, signed char, and unsigned char are collectively called the character types. Compilers have the latitude to define char to have the same range, representation, and behavior as either signed char or unsigned char. Irrespective of the choice made, {{char}} is a separate type from the other two and is not compatible with either.

...

Code Block
bgColor#FFCCCC
#include <string.h>

int main(void) {
  size_t len;
  char cstr[] = "char string";
  signed char scstr[] = "signed char string";
  unsigned char ucstr[] = "unsigned char string";

  len = strlen(cstr);
  len = strlen(scstr);  /* warns when char is unsigned */
  len = strlen(ucstr);  /* warns when char is signed */
  return 0;
}

Wiki Markup
Compiling at high warning levels
,
 in compliance with [MSC00-A. Compile cleanly at high warning levels] causes warnings to be
issue
 issued when converting from {{unsigned char\[\]}} to {{const char *}} when {{char}} is signed
,
 and from {{signed char\[\]}} to {{const char *}} when char is defined to be unsigned.  Casts are required to eliminate these warnings, but excessive casts can make code difficult to read and hide legitimate warning messages.

Wiki Markup
If this C code were to compiled using a C+\+ compiler, conversions
between
 from {{unsigned char\[\]}} to {{const char *}} and from {{signed char\[\]}} to {{const char *}} would be be flagged as errors requiring casts.

Compliant Solution

The compliant solution uses plain char for character data.

...