Why does the function `memchr()` use `int` for the argument of `char` type?

前端 未结 4 1314
逝去的感伤
逝去的感伤 2021-01-05 00:47

The following function uses int as the second argument type,

memchr(const void *buf, int ch, size_t count);

Though it is used

4条回答
  •  醉酒成梦
    2021-01-05 00:59

    All of the standard functions that deal in characters do. I think the reason is partly historical (in some pre-standard versions of C, a function couldn't take a char or unsigned char argument, just like varargs arguments can't have character type) and partly for consistency across all such functions.

    There are a few character-handling functions that have to use int in order to allow for the possibility of EOF, but memchr isn't one of them.

提交回复
热议问题