Do I need to cast to unsigned char before calling toupper(), tolower(), et al.?

前端 未结 5 1199
广开言路
广开言路 2020-11-22 14:15

A while ago, someone with high reputation here on Stack Overflow wrote in a comment that it is necessary to cast a char-argument to unsigned char b

5条回答
  •  清歌不尽
    2020-11-22 15:07

    The reference is referring to the value being representable as an unsigned char, not to it being an unsigned char. That is, the behavior is undefined if the actual value is not between 0 and UCHAR_MAX (typically 255). (Or EOF, which is basically the reason it takes an int instead of a char.)

提交回复
热议问题