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

前端 未结 5 1167
广开言路
广开言路 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:12

    Sadly Stroustrup was careless :-(
    And yes, latin letters codes should be non-negative (and no cast are required)...
    Some implementations correctly works without casting to unsigned char...
    By the some experience, it may cost a several hours to find the cause of segfault of a such toupper (when it is known that a segfault are there)...
    And there are also isupper, islower etc

提交回复
热议问题