Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > regarding << and >> operators

Reply
Thread Tools

regarding << and >> operators

 
 
onkar
Guest
Posts: n/a
 
      11-15-2006
#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

 
Reply With Quote
 
 
 
 
jaysome
Guest
Posts: n/a
 
      11-15-2006
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Confusion regarding boolean operators. Kedar Mhaswade Ruby 3 01-11-2011 11:09 PM
simple (?) question regarding the "&&" and "and" operators Philip Müller Ruby 4 04-18-2009 07:33 AM
Regarding overloading new and delete operators rohits123@gmail.com C++ 2 02-01-2007 10:56 AM
regarding * and ++ operators sam_cit@yahoo.co.in C Programming 12 12-18-2006 11:35 PM
regarding << and >> operators onkar C Programming 10 11-15-2006 11:55 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57