Proof positive the "signedness of char *" warning is useless.

Chuck Meade chuckmeade at mindspring.com
Wed Nov 30 20:58:50 UTC 2005


> In message <IIEEICKJLNEPBBDJICNGMENHJFAA.chuckmeade at mindspring.com> you wrote:
> >
> > Exactly.  It sounds like a good approach might be eliminating the 
> > warnings when the chars are being used as string or character data,
> 
> 	char c;
> 
> 	if (c > ' ') ...
> 
> Does this count as "used as character data"?
> 
> Cases like this will fail when the 8th bit is set...
> 
> Best regards,
> 
> Wolfgang Denk

Hi Wolfgang,

Yes, there are "mixed uses" that are hard to account for.  It is
obviously being used as character data by the context of the example,
but the comparison operation is more of a "computation".  And as you 
point out, this could lead to confusing operation if the MSB is set.

I suppose the problem here is that many APIs use "char *" for strings
and char for characters, and assume that only 7-bit ASCII will be used
for these characters. In this sort of code, setting the MSB and doing
comparisons is going to cause confusion.

However, if the example was just slightly different:
   char c;
   ...
   if (c > 0x20) ...

And 'c' is negative, then it seems more clear.  The code here doesn't
necessarily lead the reader to assume that we are dealing with character
data but rather 8-bit numeric data.  

I don't think there is a way to solve problems like the above with 
compiler warnings -- unless you warn on comparisons between signed chars
and char constants like ' '.

As for Rob's original issue, my vote would be for the warnings to be
eliminated by code changes/fixes, to the extent possible, rather than
globally shutting them off.  

Best regards,
Chuck





More information about the busybox mailing list