0

Hi I got this weird warning in this simple code that leaves me completely confused. I searched trough the page and I see that this is a warning to alert users to avoid using chars as index of matrix because they can be signned, but obviously this is not the case.

Here is the code:

#include <stdio.h>
#include <ctype.h>

int main() {

    char c='t';
    if (isspace(c)==0)
        printf ("%c is not a space",c);

    return (EXIT_SUCCESS);
}

my question is what is the reason of the warning? is it related with the fact that isspace expects an int as argument?

1
  • need "#include <stdlib.h> Commented Jul 15, 2014 at 9:33

1 Answer 1

1

a warning to alert users to avoid using chars as index of matrix because they can be signned, but obviously this is not the case

Actually, it is the case ... what you see is not what the compiler sees.

is it related with the fact that isspace expects an int as argument?

Yes; isspace is a macro which (in your compiler implementation) accesses an array ... take a look at your ctype.h or ask your compiler to expand macros (e.g., gcc -E) and you will see the array access.

To avoid the warning, use

if (!isspace((unsigned char)c))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.