C下<cctype>
中的一堆操作字符的函数isupper
,isalnum
,toupper
,它们的参数类型虽然都是int
,但是如果传入char
的话,是未定义行为
Like all other functions from <cctype>, the behavior of std::isalnum is undefined if the argument’s value is neither representable as unsigned char nor equal to EOF. To use these functions safely with plain chars (or signed chars), the argument should first be converted to unsigned char
所有的主流编译器在默认情况下char
都是有符号数,static_cast<unsigned char>(c)
是必须要做的类型转换