When I assign the same value to signed and unsigned short
and do a comparison it fails but it works with int
. Unless I cast one or the other to make them same types the comparison is not working.
#include<stdio.h>
int main()
{
signed short b = -10;
unsigned short c=-10;
signed int a = -10;
unsigned int d=-10;
printf("%d , %d\n",b,(unsigned short)b);
printf("%d , %d\n",(signed short)c,c);
printf("%d , %u\n",a,(unsigned int)a);
printf("%d , %u\n",(signed int )d,d);
printf("b==c %d\n", b==c);
printf("a==d %d\n", a==d);
return 0;
}
Output:
./a.out
-10 , 65526
-10 , 65526
-10 , 4294967286
-10 , 4294967286
b==c 0
a==d 1
I ran this in sun solaris sparc and hpux itanium with same output. (64 bit exes)