Does ctype.h still require unsigned char?

后端 未结 1 1740
遥遥无期
遥遥无期 2020-12-17 19:57

Traditionally, it was - strictly speaking - an error to pass a signed char to the ctype.h predicates because they were only defined for -1 to 255,

1条回答
  •  被撕碎了的回忆
    2020-12-17 20:31

    do you still strictly speaking have to use unsigned char to avoid undefined behavior in modern versions of C?

    Yes, from the C11 draft standard section 7.4 Character handling paragraph 1 says (emphasis mine):

    The header declares several functions useful for classifying and mapping characters.198) In all cases the argument is an int, the value of which shall be representable as an unsigned char or shall equal the value of the macro EOF. If the argument has any other value, the behavior is undefined.

    This also holds for draft C99 standard as well, you can find it in the same section.

    0 讨论(0)
提交回复
热议问题