regarding << and >> operators

Discussion in 'C Programming' started by onkar, Nov 15, 2006.

  1. onkar

    onkar Guest

    #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
    onkar, Nov 15, 2006
    #1
    1. Advertising

  2. onkar

    jaysome Guest

    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
    jaysome, Nov 15, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. onkar

    regarding << and >> operators

    onkar, Nov 15, 2006, in forum: C Programming
    Replies:
    10
    Views:
    639
    Dik T. Winter
    Nov 15, 2006
  2. regarding * and ++ operators

    , Dec 17, 2006, in forum: C Programming
    Replies:
    12
    Views:
    507
    August Karlstrom
    Dec 18, 2006
  3. Replies:
    2
    Views:
    314
  4. Philip Müller
    Replies:
    4
    Views:
    104
    Robert Klemme
    Apr 18, 2009
  5. Kedar Mhaswade

    Confusion regarding boolean operators.

    Kedar Mhaswade, Jan 9, 2011, in forum: Ruby
    Replies:
    3
    Views:
    105
    Kedar Mhaswade
    Jan 11, 2011
Loading...

Share This Page