Small compiler bug signed vs. unsigned char !
Ingo Krabbe
ingo@wallace.ping.de
Wed Mar 4 18:03:00 GMT 1998
hi,
I tried to compile the libz.so.1.0.4 from redhat archive (zlib...src.rpm)
The test program made an error with egcs, while it doesn't it with gcc2.7.2.2
The problem was the if--else construction:
while (n && m < 4)
{
printf(" %d %d \n", (int)*p, m);
if (*p == (Byte)(m < 2 ? 0 : 0xff)) /* Here is the conversion problem ! */
m++;
else if (*p)
m = 0;
else
m = 4 - m;
p++, n--;
}
The error is reproducable ! when compiling this code with p={0,0,255,255,255...}
you get the wrong output:
0 0
0 1
255 2
255 0
255 0
255 0
255 0
...
without the (Byte) conversion (which is actually a unsigned char) you get
0 0
0 1
255 2
255 3
I encountered a similar error with CC on a Sun Solaris 2.xx :-)
Maybe its correct what you made with your compiler. But this behaviour is not
very nice especially because there is no *Warning* !
CU INGO
More information about the Gcc-bugs
mailing list