Right shift operator

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ERE

    #1

    Right shift operator

    Pardon me if this has been asked a million times -- but I thought that
    because of generics, the right shift operator was supposed to change with C#
    2.0. I thought it was supposed to change from ">>" to "> >", to distiguish
    it from nested generics.

    But I've been using VS2005, and when I put in the new syntax I get an error
    message, whereas the old syntax, as shown in the following code continues to
    work fine. What am I missing?

    Thanks,
    Dan

    ------------------
    static void Main( )
    {
    for (int i = 32; i > 0; )
    {
    i = i >> 1;
    Console.WriteLi ne("Value: {0}", i);
    }
    }


  • Jon Skeet [C# MVP]

    #2
    Re: Right shift operator

    ERE <eaglerock@ma.u ltranet.com> wrote:[color=blue]
    > Pardon me if this has been asked a million times -- but I thought that
    > because of generics, the right shift operator was supposed to change with C#
    > 2.0. I thought it was supposed to change from ">>" to "> >", to distiguish
    > it from nested generics.
    >
    > But I've been using VS2005, and when I put in the new syntax I get an error
    > message, whereas the old syntax, as shown in the following code continues to
    > work fine. What am I missing?[/color]

    The right shift operator itself hasn't been changed in terms of what
    you write. It's been changed in terms of what one part of the compiler
    gives to the other. Instead of the parser recognising one token of
    ">>" it recognises two tokens, each of which is ">".

    --
    Jon Skeet - <skeet@pobox.co m>
    http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
    If replying to the group, please do not mail me too

    Comment

    • rossum

      #3
      Re: Right shift operator

      On Sat, 17 Dec 2005 23:33:57 -0800, "ERE" <eaglerock@ma.u ltranet.com>
      wrote:
      [color=blue]
      >Pardon me if this has been asked a million times -- but I thought that
      >because of generics, the right shift operator was supposed to change with C#
      >2.0. I thought it was supposed to change from ">>" to "> >", to distiguish
      >it from nested generics.
      >
      >But I've been using VS2005, and when I put in the new syntax I get an error
      >message, whereas the old syntax, as shown in the following code continues to
      >work fine. What am I missing?
      >
      >Thanks,
      >Dan
      >
      >------------------
      > static void Main( )
      > {
      > for (int i = 32; i > 0; )
      > {
      > i = i >> 1;
      > Console.WriteLi ne("Value: {0}", i);
      > }
      > }
      >[/color]

      There has been no change to what you type, right-shift is still ">>"
      and right-shift assignment is still ">>=". There has been a change to
      the underlying grammar to prevent the compiler treating the >> in
      nested generics as if it was a right-shift. The change is only of
      interest to compiler writers and does not affect the code that you
      write.

      HTH

      rossum

      --

      The ultimate truth is that there is no ultimate truth

      Comment

      • ERE

        #4
        Re: Right shift operator

        Thanks!

        Dan

        "Jon Skeet [C# MVP]" <skeet@pobox.co m> wrote in message
        news:MPG.1e0f27 65d2992b4c98cb5 6@msnews.micros oft.com...[color=blue]
        > ERE <eaglerock@ma.u ltranet.com> wrote:[color=green]
        >> Pardon me if this has been asked a million times -- but I thought that
        >> because of generics, the right shift operator was supposed to change with
        >> C#
        >> 2.0. I thought it was supposed to change from ">>" to "> >", to
        >> distiguish
        >> it from nested generics.
        >>
        >> But I've been using VS2005, and when I put in the new syntax I get an
        >> error
        >> message, whereas the old syntax, as shown in the following code continues
        >> to
        >> work fine. What am I missing?[/color]
        >
        > The right shift operator itself hasn't been changed in terms of what
        > you write. It's been changed in terms of what one part of the compiler
        > gives to the other. Instead of the parser recognising one token of
        > ">>" it recognises two tokens, each of which is ">".
        >
        > --
        > Jon Skeet - <skeet@pobox.co m>
        > http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
        > If replying to the group, please do not mail me too[/color]


        Comment

        Working...