(if N were to
be declared "unsigned", even more would get it wrong!)
Really? Once you
realize that C treats the value of 0 as false, and
anything else as true, then there isn't any difference
Yes. But a lot of people will get confused because they know that --
wraps from zero to ~0U and won't read the test carefully enough.
But if we're going to go into gotchas of C,
what's wrong with this code?
[compressed vertically to save space -dM]
void foo(char *s)
{ int charcount[256]; memset(charcount,0,sizeof(charcount));
for ( ; *s ; s++) { charcount[*s]++; }
}
Nothing...on machines where char is 8-bit unsigned. :-)
If char is signed, or if it's wider than 8 bits, you lose big - and
worse, you don't lose until it's called with a string that happens to
contain offending characters, so it may "work fine" in testing.
/~\ The ASCII der Mouse
\ / Ribbon Campaign
X Against HTML mouse(a)rodents.montreal.qc.ca
/ \ Email! 7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B