signed | unsigned char?

Ian Lance Taylor iant@google.com
Thu Sep 12 20:17:00 GMT 2013


On Thu, Sep 12, 2013 at 12:46 PM, ballsystemlord <doark@mail.com> wrote:
> I'm wondering what type of char I should pass to the various functions that
> deal with strings. I also wanted to know if it mattered.

You should normally pass the type 'char'.  When dealing only when
strings it rarely matters.

> I was just passing char to functions but I wanted to know how big it was and
> that's not easy to find out when you don't know if it's signed or not.

By definition sizeof(char) == 1.  You can find the minimum and maximum
valuesof char by #include <limits.h> and looking at CHAR_MIN and
CHAR_MAX.

> I tried using unsigned chars and char and then compiling with the option
> -unsigned-char (I think it's called) but I'm still getting warnings like:
>
> -wsign-compare
> XXXXXXX function expected `char' but argument is type `unsigned char'

That is as expected.

By the way, these questions are more related to C in general than to
GCC in particular.

Ian



More information about the Gcc-help mailing list