compilation warnings: 'pointer targets ... differ in signedness'

Bernd Petrovitsch bernd at firmix.at
Thu Oct 6 19:50:09 UTC 2005


On Thu, 2005-10-06 at 14:06 -0500, Rob Landley wrote:
> On Tuesday 04 October 2005 13:23, Larry Doolittle wrote:
> > 99% of what you do with chars has nothing to do with whether or
> > not they're signed.  The point of the C standard standing mute
> > on the default signedness is that the compiler can tune for whatever
> > is more efficient.  So in 99% of our uses, busybox should leave it
> > unspecified.
> 
> By that logic, short and int should also be of indeterminate sign.

Not quite.
The real difference is, that "char", "signed char" and "unsigned char"
are 3 (in words: three) different types. "char" can hold any printable
character (we ignore now UTF-8 and the like - is doesn't work in the
21st century that way anymore that simple) and you basically *cannot
calculate* with a "char".
As soon as you calculate with a "char" it turns (read: is promoted) into
a "signed char" or "unsigned char" - this depends on the compiler and
that's the only reason for the default signedness for "char"s.
"signed char" and "unsigned char" are actually the smallest integral
types with all the benefits and problems like "signed short int" vs
"unsigned short int", etc.

And yes, there situations where you must cast (or disable the warning
altogether).

	Bernd
-- 
Firmix Software GmbH                   http://www.firmix.at/
mobil: +43 664 4416156                 fax: +43 1 7890849-55
          Embedded Linux Development and Services




More information about the busybox mailing list