Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: more exhaustive list of functions that convert their arguments to char or unsigned char

...

  • Integer operands of any pointer arithmetic, including array indexing;
  • The assignment expression for the declaration of a variable length array;
  • The postfix expression preceding square brackets [] or the expression in square brackets [] of a subscripted designation of an element of an array object; and
  • Function arguments of type size_t or rsize_t (for example, an argument to a memory allocation function).

This rule also applied applies to arguments passed to library functions such as memset(), memchr(), strchr() that are truncated by the function.the following library functions that are converted to unsigned char:

  • memset()
  • memset_s()
  • fprintf() and related functions. For the length modifier c, if no l length modifier is present, the int argument is converted to an unsigned char, and the resulting character is written.
  • fputc()
  • ungetc()
  • memchr()

And to arguments to the following library functions that are converted to char:

  • strchr()
  • strrchr()

The only integer type conversions that are guaranteed to be safe for all data values and all possible conforming implementations are conversions of an integral value to a wider type of the same signedness. The C Standard, 6.3.1.3 [ISO/IEC 9899:2011], says,

...