DeepaK said:
main()
{
int a =100;
a = a>>32;
printf(" %d", a);
}
it prints "a" as 100 only....but I am expecting a = 0.....
can some one tell me the reason?
bye
Deepak\
Fixed version of your program:
#include <stdio.h>
int main(void)
{
int a = 100;
a = a>>32;
printf(" %d\n", a);
return 0;
}
temp(558)$ gcc -Wall -o foo foo.c
foo.c: In function `main':
foo.c:6: warning: right shift count >= width of type
temp(559)$ foo
100
Do you compile with warnings on? Unless int is 64 bits, you
are invoking undefined behavior. Once you do that, what you
get is up to the vagaries of fate, in gcc apparently it does
nothing for shifts >= to the size, at least for the version
I am using. Here is what the standard says:
The integer promotions are performed on each of the
operands. The type of the result is that of the promoted
left operand. If the value of the right operand is negative
or is greater than or equal to the width of the promoted
left operand, the behavior is undefined.
-David