Array subscript has type ‘char’ [-Wchar-subscripts]

后端 未结 4 2096
心在旅途
心在旅途 2021-01-21 04:52

I am trying to remove leading/trailing whitespace characters with help below helper function. When compiling i am getting warning: array subscript has type ‘char’ [-Wchar-subsc

4条回答
  •  无人共我
    2021-01-21 05:14

    The warning may be because you're passing a char to the isspace() macro. The implementation of isspace() may be via array indexing. (The argument to the isspace() macro is defined to be an integer the value of which can fit in an unsignedchar).

    I've just looked at ctype.h in GNU libc, and while there's a complicated mess of macros and functions, somewhere in the definition of isspace() there's an array being indexed.

    See if isspace((unsigned char) *str) gets rid of the warning.

提交回复
热议问题