From: gthaker@fergie.dnet.ge.com (Gautam H. Thaker) Subject: possible GCC bug in signed and unsigned short compares Date: 8 Feb 1993 12:34:51
The following program compares unsigned int with a signed int
and prints the result. It than does the same for unsigned short
and signed short. It seems to me that 'ans' in both cases should
be the same, and that it should be "0". Sun's ANSI compiler
seems to handle this ok, as does GCC with "-traditional" flag.
Is this a bug? I have tested this on SUN Sparc GCC v2.1 and on
486 Linux GCC v2.3.3. Same results.
void main() {
int i;
unsigned j;
short is;
unsigned short js;
int ans;
i = -1;
j = 5;
ans = i < j; /* comparing unsigned int with signed int */
printf("ans %d\n", ans); /* answer should be 0. Not sure */
is = -1;
js = 5;
ans = is < js; /* comparing unsigned short with signed short */
printf("ans %d\n", ans); /* answer should be 0. Not sure */
}