I am expecting zero value of 16-bit signed value 0x8000 after left shift by 2.
Following is my code
int main()
{
register signed short val1 = 0x8000 ;
signed short val2 ;
val2 = ( ( val1 > 2 ) ; /* val2 should be 0. */
printf( "nval2 is :%xn", val2 ) ; /* But Val2 is ffff8000 */
return 0 ;
}
$ gcc myfile.c
$ ./a.out
I have verified the same behavior with 32-bit compilers and expected (val2=0) with 16-bit compiler. I can correct this by shifting 18 in place of 2 as a workaround. I want some verify my understanding for this point and another way to get expected result (if any).