On 14 Nov 2006 22:08:34 -0800, "onkar" <> wrote:
>#include<stdio.h>
>int main(void){
> printf("%d %d\n",32<<1,32<<0);
> printf("%d %d\n",32<<-1,32<<-0);
><----------------------------------see here
> printf("%d %d\n",32>>1,32>>0);
> printf("%d %d\n",32>>-1,32>>-0);
><----------------------------------and here
>
> return 0;
>}
>
>
>
>$ make
>gcc -Wall -g -o test test.c
>test.c: In function `main':
>test.c:4: warning: left shift count is negative
>test.c:6: warning: right shift count is negative
>$ ./test
>64 32
>0 32
>16 32
>0 32
Looks like a bug to me and PC-lint agrees with the result:
--- Module: c.c (C)
_
printf("%d %d\n",32<<-1,32<<-0);
c.c(4) : Warning 504: Unusual shift operation (unusually formed right
argument)
c.c(4) : Info 778: Constant expression evaluates to 0 in operation
'<<'
c.c(4) : Info 778: Constant expression evaluates to 0 in operation '-'
c.c(4) : Warning 504: Unusual shift operation (unusually formed right
argument)
_
printf("%d %d\n",32>>-1,32>>-0);
c.c(6) : Warning 504: Unusual shift operation (unusually formed right
argument)
c.c(6) : Info 778: Constant expression evaluates to 0 in operation
'>>'
c.c(6) : Info 778: Constant expression evaluates to 0 in operation '-'
c.c(6) : Warning 504: Unusual shift operation (unusually formed right
argument)
--- Global Wrap-up
Note 900: Successful completion, 8 messages produced
Tool returned code: 0
Best regards
--
jay
http://www.gimpel.com/
http://www.gimpel.com/html/bugs.htm