Connecting Tech Pros Worldwide Help | Site Map

what does shifting "negative" times mean ?

Newbie
 
Join Date: Jul 2007
Posts: 18
#1: Jul 18 '07
I use a Turbo C compiler, and the value i get for say, 32<<-1 is 0. In fact this is the case for any integer I take.

Kindly somebody help what's happening ... ?
Moreover, is there any difference if I try this with gcc. ( i don't have it currently .. :(
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#2: Jul 18 '07

re: what does shifting "negative" times mean ?


Quote:

Originally Posted by ajaygargnsit

I use a Turbo C compiler, and the value i get for say, 32<<-1 is 0. In fact this is the case for any integer I take.

Kindly somebody help what's happening ... ?
Moreover, is there any difference if I try this with gcc. ( i don't have it currently .. :(

This is what the C99 Standard has to say about it:

"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."


kind regards,

Jos
Newbie
 
Join Date: Jul 2007
Posts: 18
#3: Jul 18 '07

re: what does shifting "negative" times mean ?


Thanks for clarifying.
Reply