Feature request:....

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

    Feature request:....

    When setting the [Flags] attribute on an enum, why should I have to specify
    powers of 2 when the compiler should see this is a bitfield and set the
    range accordingly, why should I have to do the work that the compiler can
    do?


    To me this is just asking for errors to be introduced by offloading this
    responsibility onto the programmer.

    Sure we should be able to override a value in the bitfield enum to allow
    ranges like All = Enum1Val | Enum2Val; etc.



  • Stoyan Damov

    #2
    Re: Feature request:....

    To me, the automatic compiler support is asking for errors. If you reorder
    your enum, you break their values, e.g. an enum saved to a file (before the
    reordering), won't be read properly (after the reordering). If you are too
    lazy to set bit masks, you can always define enums in this way:

    [Flags]
    public enum Whatever
    {
    None = 0,
    Flag1 = 1,
    Flag2 = Flag1 << 1,
    Flag3 = Flag2 << 1,
    // etc.
    CheckMask = Flag1 | ... | FlagN
    }

    Cheers,
    Stoyan

    "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
    news:%23Rx7p79j DHA.3312@tk2msf tngp13.phx.gbl. ..[color=blue]
    > When setting the [Flags] attribute on an enum, why should I have to[/color]
    specify[color=blue]
    > powers of 2 when the compiler should see this is a bitfield and set the
    > range accordingly, why should I have to do the work that the compiler can
    > do?
    >
    >
    > To me this is just asking for errors to be introduced by offloading this
    > responsibility onto the programmer.
    >
    > Sure we should be able to override a value in the bitfield enum to allow
    > ranges like All = Enum1Val | Enum2Val; etc.
    >
    >
    >[/color]


    Comment

    • Mr.Tickle

      #3
      Re: Feature request:....

      Well, we have already automatic support for enums, its overridable, so why
      not have it consistant to that of non Flag enums?

      If we are lazy? Enums currently (for non bitmasks) are already defined.
      Youre lazy argument falls flat on its face.



      "Stoyan Damov" <stoyand@code.b g> wrote in message
      news:eN1tbaXkDH A.2364@TK2MSFTN GP11.phx.gbl...[color=blue]
      > To me, the automatic compiler support is asking for errors. If you reorder
      > your enum, you break their values, e.g. an enum saved to a file (before[/color]
      the[color=blue]
      > reordering), won't be read properly (after the reordering). If you are too
      > lazy to set bit masks, you can always define enums in this way:
      >
      > [Flags]
      > public enum Whatever
      > {
      > None = 0,
      > Flag1 = 1,
      > Flag2 = Flag1 << 1,
      > Flag3 = Flag2 << 1,
      > // etc.
      > CheckMask = Flag1 | ... | FlagN
      > }
      >
      > Cheers,
      > Stoyan
      >
      > "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
      > news:%23Rx7p79j DHA.3312@tk2msf tngp13.phx.gbl. ..[color=green]
      > > When setting the [Flags] attribute on an enum, why should I have to[/color]
      > specify[color=green]
      > > powers of 2 when the compiler should see this is a bitfield and set the
      > > range accordingly, why should I have to do the work that the compiler[/color][/color]
      can[color=blue][color=green]
      > > do?
      > >
      > >
      > > To me this is just asking for errors to be introduced by offloading this
      > > responsibility onto the programmer.
      > >
      > > Sure we should be able to override a value in the bitfield enum to allow
      > > ranges like All = Enum1Val | Enum2Val; etc.
      > >
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Stoyan Damov

        #4
        Re: Feature request:....

        I couldn't understand anything. Sorry if I have offended you in any way.

        Cheers,
        Stoyan

        "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
        news:ubWKWnZkDH A.424@TK2MSFTNG P10.phx.gbl...[color=blue]
        > Well, we have already automatic support for enums, its overridable, so why
        > not have it consistant to that of non Flag enums?
        >
        > If we are lazy? Enums currently (for non bitmasks) are already defined.
        > Youre lazy argument falls flat on its face.
        >
        >
        >
        > "Stoyan Damov" <stoyand@code.b g> wrote in message
        > news:eN1tbaXkDH A.2364@TK2MSFTN GP11.phx.gbl...[color=green]
        > > To me, the automatic compiler support is asking for errors. If you[/color][/color]
        reorder[color=blue][color=green]
        > > your enum, you break their values, e.g. an enum saved to a file (before[/color]
        > the[color=green]
        > > reordering), won't be read properly (after the reordering). If you are[/color][/color]
        too[color=blue][color=green]
        > > lazy to set bit masks, you can always define enums in this way:
        > >
        > > [Flags]
        > > public enum Whatever
        > > {
        > > None = 0,
        > > Flag1 = 1,
        > > Flag2 = Flag1 << 1,
        > > Flag3 = Flag2 << 1,
        > > // etc.
        > > CheckMask = Flag1 | ... | FlagN
        > > }
        > >
        > > Cheers,
        > > Stoyan
        > >
        > > "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
        > > news:%23Rx7p79j DHA.3312@tk2msf tngp13.phx.gbl. ..[color=darkred]
        > > > When setting the [Flags] attribute on an enum, why should I have to[/color]
        > > specify[color=darkred]
        > > > powers of 2 when the compiler should see this is a bitfield and set[/color][/color][/color]
        the[color=blue][color=green][color=darkred]
        > > > range accordingly, why should I have to do the work that the compiler[/color][/color]
        > can[color=green][color=darkred]
        > > > do?
        > > >
        > > >
        > > > To me this is just asking for errors to be introduced by offloading[/color][/color][/color]
        this[color=blue][color=green][color=darkred]
        > > > responsibility onto the programmer.
        > > >
        > > > Sure we should be able to override a value in the bitfield enum to[/color][/color][/color]
        allow[color=blue][color=green][color=darkred]
        > > > ranges like All = Enum1Val | Enum2Val; etc.
        > > >
        > > >
        > > >[/color]
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Mr.Tickle

          #5
          Re: Feature request:....

          Simple. Enums are currently automatic, except they are AUTOMATIC INCORRECTLY
          when FLAGS attribute is set.

          Its INCORRECT behaviour for the Flags attribute. Since when is a bitfield
          automaticly set to 1, 2, 3, 4, 5`?? Thats what it does.

          What I am asking is if we can have it automatically set to 1, 2, 4, 8, 16...
          CORRECTLY.



          "Stoyan Damov" <stoyand@code.b g> wrote in message
          news:e8eC#pZkDH A.2268@TK2MSFTN GP12.phx.gbl...[color=blue]
          > I couldn't understand anything. Sorry if I have offended you in any way.
          >
          > Cheers,
          > Stoyan
          >
          > "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
          > news:ubWKWnZkDH A.424@TK2MSFTNG P10.phx.gbl...[color=green]
          > > Well, we have already automatic support for enums, its overridable, so[/color][/color]
          why[color=blue][color=green]
          > > not have it consistant to that of non Flag enums?
          > >
          > > If we are lazy? Enums currently (for non bitmasks) are already defined.
          > > Youre lazy argument falls flat on its face.
          > >
          > >
          > >
          > > "Stoyan Damov" <stoyand@code.b g> wrote in message
          > > news:eN1tbaXkDH A.2364@TK2MSFTN GP11.phx.gbl...[color=darkred]
          > > > To me, the automatic compiler support is asking for errors. If you[/color][/color]
          > reorder[color=green][color=darkred]
          > > > your enum, you break their values, e.g. an enum saved to a file[/color][/color][/color]
          (before[color=blue][color=green]
          > > the[color=darkred]
          > > > reordering), won't be read properly (after the reordering). If you are[/color][/color]
          > too[color=green][color=darkred]
          > > > lazy to set bit masks, you can always define enums in this way:
          > > >
          > > > [Flags]
          > > > public enum Whatever
          > > > {
          > > > None = 0,
          > > > Flag1 = 1,
          > > > Flag2 = Flag1 << 1,
          > > > Flag3 = Flag2 << 1,
          > > > // etc.
          > > > CheckMask = Flag1 | ... | FlagN
          > > > }
          > > >
          > > > Cheers,
          > > > Stoyan
          > > >
          > > > "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
          > > > news:%23Rx7p79j DHA.3312@tk2msf tngp13.phx.gbl. ..
          > > > > When setting the [Flags] attribute on an enum, why should I have to
          > > > specify
          > > > > powers of 2 when the compiler should see this is a bitfield and set[/color][/color]
          > the[color=green][color=darkred]
          > > > > range accordingly, why should I have to do the work that the[/color][/color][/color]
          compiler[color=blue][color=green]
          > > can[color=darkred]
          > > > > do?
          > > > >
          > > > >
          > > > > To me this is just asking for errors to be introduced by offloading[/color][/color]
          > this[color=green][color=darkred]
          > > > > responsibility onto the programmer.
          > > > >
          > > > > Sure we should be able to override a value in the bitfield enum to[/color][/color]
          > allow[color=green][color=darkred]
          > > > > ranges like All = Enum1Val | Enum2Val; etc.
          > > > >
          > > > >
          > > > >
          > > >
          > > >[/color]
          > >
          > >[/color]
          >
          >[/color]


          Comment

          • Eric Gunnerson [MS]

            #6
            Re: Feature request:....

            It's fairly common for people to define values that are combinations of the
            others:

            enum Test
            {
            First = 0x01,
            Second = 0x02,
            AllBits = 0x03,
            NoBits = 0x00,

            }

            --
            Eric Gunnerson

            Visit the C# product team at http://www.csharp.net
            Eric's blog is at http://blogs.gotdotnet.com/ericgu/

            This posting is provided "AS IS" with no warranties, and confers no rights.
            "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
            news:%23Rx7p79j DHA.3312@tk2msf tngp13.phx.gbl. ..[color=blue]
            > When setting the [Flags] attribute on an enum, why should I have to[/color]
            specify[color=blue]
            > powers of 2 when the compiler should see this is a bitfield and set the
            > range accordingly, why should I have to do the work that the compiler can
            > do?
            >
            >
            > To me this is just asking for errors to be introduced by offloading this
            > responsibility onto the programmer.
            >
            > Sure we should be able to override a value in the bitfield enum to allow
            > ranges like All = Enum1Val | Enum2Val; etc.
            >
            >
            >[/color]


            Comment

            • Mr.Tickle

              #7
              Re: Feature request:....

              So if we just say

              [Flags]
              enum Test
              {
              First,
              Second,
              Third,
              Fourth
              }

              Guess what the compiler generates?

              First = 0, Second = 1 , Third = 2, Fourth = 3

              So thats correct behaviour for a Flag? Dont make me laugh.



              "Eric Gunnerson [MS]" <ericgu@online. microsoft.com> wrote in message
              news:OBZgZpdkDH A.2444@TK2MSFTN GP09.phx.gbl...[color=blue]
              > It's fairly common for people to define values that are combinations of[/color]
              the[color=blue]
              > others:
              >
              > enum Test
              > {
              > First = 0x01,
              > Second = 0x02,
              > AllBits = 0x03,
              > NoBits = 0x00,
              >
              > }
              >
              > --
              > Eric Gunnerson
              >
              > Visit the C# product team at http://www.csharp.net
              > Eric's blog is at http://blogs.gotdotnet.com/ericgu/
              >
              > This posting is provided "AS IS" with no warranties, and confers no[/color]
              rights.[color=blue]
              > "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
              > news:%23Rx7p79j DHA.3312@tk2msf tngp13.phx.gbl. ..[color=green]
              > > When setting the [Flags] attribute on an enum, why should I have to[/color]
              > specify[color=green]
              > > powers of 2 when the compiler should see this is a bitfield and set the
              > > range accordingly, why should I have to do the work that the compiler[/color][/color]
              can[color=blue][color=green]
              > > do?
              > >
              > >
              > > To me this is just asking for errors to be introduced by offloading this
              > > responsibility onto the programmer.
              > >
              > > Sure we should be able to override a value in the bitfield enum to allow
              > > ranges like All = Enum1Val | Enum2Val; etc.
              > >
              > >
              > >[/color]
              >
              >[/color]


              Comment

              • ozbear

                #8
                Re: Feature request:....

                On Tue, 14 Oct 2003 08:35:03 +0200, "Mr.Tickle" <MrTickle@mrmen .com>
                wrote:
                [color=blue]
                >So if we just say
                >
                >[Flags]
                >enum Test
                >{
                > First,
                > Second,
                > Third,
                > Fourth
                >}
                >
                >Guess what the compiler generates?
                >
                >First = 0, Second = 1 , Third = 2, Fourth = 3
                >
                >So thats correct behaviour for a Flag? Dont make me laugh.
                >
                >
                >
                >"Eric Gunnerson [MS]" <ericgu@online. microsoft.com> wrote in message
                >news:OBZgZpdkD HA.2444@TK2MSFT NGP09.phx.gbl.. .[color=green]
                >> It's fairly common for people to define values that are combinations of[/color]
                >the[color=green]
                >> others:
                >>
                >> enum Test
                >> {
                >> First = 0x01,
                >> Second = 0x02,
                >> AllBits = 0x03,
                >> NoBits = 0x00,
                >>
                >> }
                >>
                >> --
                >> Eric Gunnerson
                >>
                >> Visit the C# product team at http://www.csharp.net
                >> Eric's blog is at http://blogs.gotdotnet.com/ericgu/
                >>
                >> This posting is provided "AS IS" with no warranties, and confers no[/color]
                >rights.[color=green]
                >> "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
                >> news:%23Rx7p79j DHA.3312@tk2msf tngp13.phx.gbl. ..[color=darkred]
                >> > When setting the [Flags] attribute on an enum, why should I have to[/color]
                >> specify[color=darkred]
                >> > powers of 2 when the compiler should see this is a bitfield and set the
                >> > range accordingly, why should I have to do the work that the compiler[/color][/color]
                >can[color=green][color=darkred]
                >> > do?
                >> >
                >> >
                >> > To me this is just asking for errors to be introduced by offloading this
                >> > responsibility onto the programmer.
                >> >
                >> > Sure we should be able to override a value in the bitfield enum to allow
                >> > ranges like All = Enum1Val | Enum2Val; etc.
                >> >
                >> >
                >> >[/color]
                >>
                >>[/color]
                >
                >[/color]

                Idiot

                Comment

                • ozbear

                  #9
                  Re: Feature request:....

                  On Mon, 13 Oct 2003 18:18:39 +0200, "Mr.Tickle" <MrTickle@mrmen .com>
                  wrote:
                  [color=blue]
                  >Simple. Enums are currently automatic, except they are AUTOMATIC INCORRECTLY
                  >when FLAGS attribute is set.
                  >
                  >Its INCORRECT behaviour for the Flags attribute. Since when is a bitfield
                  >automaticly set to 1, 2, 3, 4, 5`?? Thats what it does.
                  >
                  >What I am asking is if we can have it automatically set to 1, 2, 4, 8, 16...
                  >CORRECTLY.
                  >
                  >
                  >
                  >"Stoyan Damov" <stoyand@code.b g> wrote in message
                  >news:e8eC#pZkD HA.2268@TK2MSFT NGP12.phx.gbl.. .[color=green]
                  >> I couldn't understand anything. Sorry if I have offended you in any way.
                  >>
                  >> Cheers,
                  >> Stoyan
                  >>
                  >> "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
                  >> news:ubWKWnZkDH A.424@TK2MSFTNG P10.phx.gbl...[color=darkred]
                  >> > Well, we have already automatic support for enums, its overridable, so[/color][/color]
                  >why[color=green][color=darkred]
                  >> > not have it consistant to that of non Flag enums?
                  >> >
                  >> > If we are lazy? Enums currently (for non bitmasks) are already defined.
                  >> > Youre lazy argument falls flat on its face.
                  >> >
                  >> >
                  >> >
                  >> > "Stoyan Damov" <stoyand@code.b g> wrote in message
                  >> > news:eN1tbaXkDH A.2364@TK2MSFTN GP11.phx.gbl...
                  >> > > To me, the automatic compiler support is asking for errors. If you[/color]
                  >> reorder[color=darkred]
                  >> > > your enum, you break their values, e.g. an enum saved to a file[/color][/color]
                  >(before[color=green][color=darkred]
                  >> > the
                  >> > > reordering), won't be read properly (after the reordering). If you are[/color]
                  >> too[color=darkred]
                  >> > > lazy to set bit masks, you can always define enums in this way:
                  >> > >
                  >> > > [Flags]
                  >> > > public enum Whatever
                  >> > > {
                  >> > > None = 0,
                  >> > > Flag1 = 1,
                  >> > > Flag2 = Flag1 << 1,
                  >> > > Flag3 = Flag2 << 1,
                  >> > > // etc.
                  >> > > CheckMask = Flag1 | ... | FlagN
                  >> > > }
                  >> > >
                  >> > > Cheers,
                  >> > > Stoyan
                  >> > >
                  >> > > "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
                  >> > > news:%23Rx7p79j DHA.3312@tk2msf tngp13.phx.gbl. ..
                  >> > > > When setting the [Flags] attribute on an enum, why should I have to
                  >> > > specify
                  >> > > > powers of 2 when the compiler should see this is a bitfield and set[/color]
                  >> the[color=darkred]
                  >> > > > range accordingly, why should I have to do the work that the[/color][/color]
                  >compiler[color=green][color=darkred]
                  >> > can
                  >> > > > do?
                  >> > > >
                  >> > > >
                  >> > > > To me this is just asking for errors to be introduced by offloading[/color]
                  >> this[color=darkred]
                  >> > > > responsibility onto the programmer.
                  >> > > >
                  >> > > > Sure we should be able to override a value in the bitfield enum to[/color]
                  >> allow[color=darkred]
                  >> > > > ranges like All = Enum1Val | Enum2Val; etc.
                  >> > > >
                  >> > > >
                  >> > > >
                  >> > >
                  >> > >
                  >> >
                  >> >[/color]
                  >>
                  >>[/color]
                  >
                  >[/color]

                  Idiot

                  Comment

                  • Mr.Tickle

                    #10
                    Re: Feature request:....

                    yankstain

                    "ozbear" <ozbear@no.bigp ond.spam.com> wrote in message
                    news:3f8bc8cc.1 91775406@news-server...[color=blue]
                    > On Mon, 13 Oct 2003 18:18:39 +0200, "Mr.Tickle" <MrTickle@mrmen .com>
                    > wrote:
                    >[color=green]
                    > >Simple. Enums are currently automatic, except they are AUTOMATIC[/color][/color]
                    INCORRECTLY[color=blue][color=green]
                    > >when FLAGS attribute is set.
                    > >
                    > >Its INCORRECT behaviour for the Flags attribute. Since when is a bitfield
                    > >automaticly set to 1, 2, 3, 4, 5`?? Thats what it does.
                    > >
                    > >What I am asking is if we can have it automatically set to 1, 2, 4, 8,[/color][/color]
                    16...[color=blue][color=green]
                    > >CORRECTLY.
                    > >
                    > >
                    > >
                    > >"Stoyan Damov" <stoyand@code.b g> wrote in message
                    > >news:e8eC#pZkD HA.2268@TK2MSFT NGP12.phx.gbl.. .[color=darkred]
                    > >> I couldn't understand anything. Sorry if I have offended you in any[/color][/color][/color]
                    way.[color=blue][color=green][color=darkred]
                    > >>
                    > >> Cheers,
                    > >> Stoyan
                    > >>
                    > >> "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
                    > >> news:ubWKWnZkDH A.424@TK2MSFTNG P10.phx.gbl...
                    > >> > Well, we have already automatic support for enums, its overridable,[/color][/color][/color]
                    so[color=blue][color=green]
                    > >why[color=darkred]
                    > >> > not have it consistant to that of non Flag enums?
                    > >> >
                    > >> > If we are lazy? Enums currently (for non bitmasks) are already[/color][/color][/color]
                    defined.[color=blue][color=green][color=darkred]
                    > >> > Youre lazy argument falls flat on its face.
                    > >> >
                    > >> >
                    > >> >
                    > >> > "Stoyan Damov" <stoyand@code.b g> wrote in message
                    > >> > news:eN1tbaXkDH A.2364@TK2MSFTN GP11.phx.gbl...
                    > >> > > To me, the automatic compiler support is asking for errors. If you
                    > >> reorder
                    > >> > > your enum, you break their values, e.g. an enum saved to a file[/color]
                    > >(before[color=darkred]
                    > >> > the
                    > >> > > reordering), won't be read properly (after the reordering). If you[/color][/color][/color]
                    are[color=blue][color=green][color=darkred]
                    > >> too
                    > >> > > lazy to set bit masks, you can always define enums in this way:
                    > >> > >
                    > >> > > [Flags]
                    > >> > > public enum Whatever
                    > >> > > {
                    > >> > > None = 0,
                    > >> > > Flag1 = 1,
                    > >> > > Flag2 = Flag1 << 1,
                    > >> > > Flag3 = Flag2 << 1,
                    > >> > > // etc.
                    > >> > > CheckMask = Flag1 | ... | FlagN
                    > >> > > }
                    > >> > >
                    > >> > > Cheers,
                    > >> > > Stoyan
                    > >> > >
                    > >> > > "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
                    > >> > > news:%23Rx7p79j DHA.3312@tk2msf tngp13.phx.gbl. ..
                    > >> > > > When setting the [Flags] attribute on an enum, why should I have[/color][/color][/color]
                    to[color=blue][color=green][color=darkred]
                    > >> > > specify
                    > >> > > > powers of 2 when the compiler should see this is a bitfield and[/color][/color][/color]
                    set[color=blue][color=green][color=darkred]
                    > >> the
                    > >> > > > range accordingly, why should I have to do the work that the[/color]
                    > >compiler[color=darkred]
                    > >> > can
                    > >> > > > do?
                    > >> > > >
                    > >> > > >
                    > >> > > > To me this is just asking for errors to be introduced by[/color][/color][/color]
                    offloading[color=blue][color=green][color=darkred]
                    > >> this
                    > >> > > > responsibility onto the programmer.
                    > >> > > >
                    > >> > > > Sure we should be able to override a value in the bitfield enum[/color][/color][/color]
                    to[color=blue][color=green][color=darkred]
                    > >> allow
                    > >> > > > ranges like All = Enum1Val | Enum2Val; etc.
                    > >> > > >
                    > >> > > >
                    > >> > > >
                    > >> > >
                    > >> > >
                    > >> >
                    > >> >
                    > >>
                    > >>[/color]
                    > >
                    > >[/color]
                    >
                    > Idiot[/color]


                    Comment

                    • ozbear

                      #11
                      Re: Feature request:....

                      On Mon, 13 Oct 2003 15:35:46 -0700, "Eric Gunnerson [MS]"
                      <ericgu@online. microsoft.com> wrote:
                      [color=blue]
                      >It's fairly common for people to define values that are combinations of the
                      >others:
                      >
                      >enum Test
                      >{
                      > First = 0x01,
                      > Second = 0x02,
                      > AllBits = 0x03,
                      > NoBits = 0x00,
                      >
                      >}
                      >
                      >--
                      >Eric Gunnerson
                      >[/color]

                      The documentation does seem to be incorrect. I am using the 1.1
                      framework, if that matters, and given the declaration:

                      enum answer {yes, no maybe};

                      i can declare a variable of type -answer- and use the C# OR
                      operator...

                      answer test = answer.yes | answer.no;

                      According to the doco, I need the [Flags] attribute applied to my
                      -answer- enumeration, yet the C# compiler accepts the above test =
                      assignment without complaint. In other words...the presence or
                      absence of [Flags] makes no difference to the /assignment/.

                      I accept that it will affect other things like ToString(), etc.

                      Oz

                      Comment

                      • Mr.Tickle

                        #12
                        Re: Feature request:....

                        The compiler generates 0, 1, 2, 3, 4, 5, 6 which is NOT bitfield values in
                        powers of 2, even the flags attributem, thats the issue, its INCORRECT
                        values by default, sure people set them but its INCORRECT otherwise, so go
                        ahead and act the egotistical yankstain and ship incorrect products.

                        I just laugh at thee errors. Im on the other side of the wall dont forget
                        and will abuse those errors.

                        "ozbear" <ozbear@no.bigp ond.spam.com> wrote in message
                        news:3f8bc8f2.1 91812953@news-server...[color=blue]
                        > On Mon, 13 Oct 2003 15:35:46 -0700, "Eric Gunnerson [MS]"
                        > <ericgu@online. microsoft.com> wrote:
                        >[color=green]
                        > >It's fairly common for people to define values that are combinations of[/color][/color]
                        the[color=blue][color=green]
                        > >others:
                        > >
                        > >enum Test
                        > >{
                        > > First = 0x01,
                        > > Second = 0x02,
                        > > AllBits = 0x03,
                        > > NoBits = 0x00,
                        > >
                        > >}
                        > >
                        > >--
                        > >Eric Gunnerson
                        > >[/color]
                        >
                        > The documentation does seem to be incorrect. I am using the 1.1
                        > framework, if that matters, and given the declaration:
                        >
                        > enum answer {yes, no maybe};
                        >
                        > i can declare a variable of type -answer- and use the C# OR
                        > operator...
                        >
                        > answer test = answer.yes | answer.no;
                        >
                        > According to the doco, I need the [Flags] attribute applied to my
                        > -answer- enumeration, yet the C# compiler accepts the above test =
                        > assignment without complaint. In other words...the presence or
                        > absence of [Flags] makes no difference to the /assignment/.
                        >
                        > I accept that it will affect other things like ToString(), etc.
                        >
                        > Oz[/color]


                        Comment

                        • Jon Skeet [C# MVP]

                          #13
                          Re: Feature request:....

                          ozbear <ozbear@no.bigp ond.spam.com> wrote:[color=blue]
                          > The documentation does seem to be incorrect. I am using the 1.1
                          > framework, if that matters, and given the declaration:
                          >
                          > enum answer {yes, no maybe};
                          >
                          > i can declare a variable of type -answer- and use the C# OR
                          > operator...
                          >
                          > answer test = answer.yes | answer.no;
                          >
                          > According to the doco, I need the [Flags] attribute applied to my
                          > -answer- enumeration, yet the C# compiler accepts the above test =
                          > assignment without complaint. In other words...the presence or
                          > absence of [Flags] makes no difference to the /assignment/.
                          >
                          > I accept that it will affect other things like ToString(), etc.[/color]

                          It should work as per the above according to sectino 14.10.2 of the
                          ECMA spec.

                          The documentation you were talking about is the FlagsAttribute remarks,
                          presumably? If so, it's quite an interesting case - it's up to a
                          language to decide what it allows, so I don't think the FlagAttribute
                          documentation should really be talking about that at all. What it
                          could/should be talking about is that when [Flags] is applied, bitwise
                          operations are *expected* to give useful results (whereas they may not
                          otherwise). A language *could* decide to only allow bitwise operations
                          on enumerations which are marked with the [Flags] attribute, of course.

                          --
                          Jon Skeet - <skeet@pobox.co m>
                          Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

                          If replying to the group, please do not mail me too

                          Comment

                          • Mr.Tickle

                            #14
                            Re: Feature request:....

                            [Flags]
                            enum bitfield
                            {
                            one,
                            two,
                            three,
                            four,
                            five,
                            six,
                            all = one | two | three | four | five | six
                            }

                            man thats gonna throw up some interesting results, thanks to Eric
                            Gunnarson's ignorance.


                            Three cheers for da man that supports bad code like the above. Bitfields
                            should be set to the base of the machine, ie powers of 2, you dumbschmuck.

                            Flags in reality does jack all, except permit logical operators on enums, so
                            lets look the other way when it comes to the above and yet claim from the
                            rooftops that C# is da biz for safe coding, well it aint in the above case.





                            "Eric Gunnerson [MS]" <ericgu@online. microsoft.com> wrote in message
                            news:OBZgZpdkDH A.2444@TK2MSFTN GP09.phx.gbl...[color=blue]
                            > It's fairly common for people to define values that are combinations of[/color]
                            the[color=blue]
                            > others:
                            >
                            > enum Test
                            > {
                            > First = 0x01,
                            > Second = 0x02,
                            > AllBits = 0x03,
                            > NoBits = 0x00,
                            >
                            > }
                            >
                            > --
                            > Eric Gunnerson
                            >
                            > Visit the C# product team at http://www.csharp.net
                            > Eric's blog is at http://blogs.gotdotnet.com/ericgu/
                            >
                            > This posting is provided "AS IS" with no warranties, and confers no[/color]
                            rights.[color=blue]
                            > "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
                            > news:%23Rx7p79j DHA.3312@tk2msf tngp13.phx.gbl. ..[color=green]
                            > > When setting the [Flags] attribute on an enum, why should I have to[/color]
                            > specify[color=green]
                            > > powers of 2 when the compiler should see this is a bitfield and set the
                            > > range accordingly, why should I have to do the work that the compiler[/color][/color]
                            can[color=blue][color=green]
                            > > do?
                            > >
                            > >
                            > > To me this is just asking for errors to be introduced by offloading this
                            > > responsibility onto the programmer.
                            > >
                            > > Sure we should be able to override a value in the bitfield enum to allow
                            > > ranges like All = Enum1Val | Enum2Val; etc.
                            > >
                            > >
                            > >[/color]
                            >
                            >[/color]


                            Comment

                            • Mr.Tickle

                              #15
                              Re: Feature request:....

                              I would like to see you attempt an & operator on those values ROFL

                              Assuming it starts at 0 for bitfield.one. What if I want to pick off the
                              value bitfield.four? Im screwed.


                              Sure sure go ahead, say "but you have to set them all in powers of 2
                              yourself", well what if i dont want to and just want the following

                              [Flags]
                              enum bitfield
                              {
                              None = 0,
                              one,
                              two,
                              three,
                              four,
                              five,
                              six,
                              all = one | two | three | four | five | six
                              }

                              Well the above SHOULD work, but it doesnt because you DEFAULT to non base 2
                              values.

                              Take yer cranium from yer rectum ye ninney.







                              "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
                              news:OJNVL7jkDH A.2416@TK2MSFTN GP10.phx.gbl...[color=blue]
                              > [Flags]
                              > enum bitfield
                              > {
                              > one,
                              > two,
                              > three,
                              > four,
                              > five,
                              > six,
                              > all = one | two | three | four | five | six
                              > }
                              >
                              > man thats gonna throw up some interesting results, thanks to Eric
                              > Gunnarson's ignorance.
                              >
                              >
                              > Three cheers for da man that supports bad code like the above. Bitfields
                              > should be set to the base of the machine, ie powers of 2, you dumbschmuck.
                              >
                              > Flags in reality does jack all, except permit logical operators on enums,[/color]
                              so[color=blue]
                              > lets look the other way when it comes to the above and yet claim from the
                              > rooftops that C# is da biz for safe coding, well it aint in the above[/color]
                              case.[color=blue]
                              >
                              >
                              >
                              >
                              >
                              > "Eric Gunnerson [MS]" <ericgu@online. microsoft.com> wrote in message
                              > news:OBZgZpdkDH A.2444@TK2MSFTN GP09.phx.gbl...[color=green]
                              > > It's fairly common for people to define values that are combinations of[/color]
                              > the[color=green]
                              > > others:
                              > >
                              > > enum Test
                              > > {
                              > > First = 0x01,
                              > > Second = 0x02,
                              > > AllBits = 0x03,
                              > > NoBits = 0x00,
                              > >
                              > > }
                              > >
                              > > --
                              > > Eric Gunnerson
                              > >
                              > > Visit the C# product team at http://www.csharp.net
                              > > Eric's blog is at http://blogs.gotdotnet.com/ericgu/
                              > >
                              > > This posting is provided "AS IS" with no warranties, and confers no[/color]
                              > rights.[color=green]
                              > > "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
                              > > news:%23Rx7p79j DHA.3312@tk2msf tngp13.phx.gbl. ..[color=darkred]
                              > > > When setting the [Flags] attribute on an enum, why should I have to[/color]
                              > > specify[color=darkred]
                              > > > powers of 2 when the compiler should see this is a bitfield and set[/color][/color][/color]
                              the[color=blue][color=green][color=darkred]
                              > > > range accordingly, why should I have to do the work that the compiler[/color][/color]
                              > can[color=green][color=darkred]
                              > > > do?
                              > > >
                              > > >
                              > > > To me this is just asking for errors to be introduced by offloading[/color][/color][/color]
                              this[color=blue][color=green][color=darkred]
                              > > > responsibility onto the programmer.
                              > > >
                              > > > Sure we should be able to override a value in the bitfield enum to[/color][/color][/color]
                              allow[color=blue][color=green][color=darkred]
                              > > > ranges like All = Enum1Val | Enum2Val; etc.
                              > > >
                              > > >
                              > > >[/color]
                              > >
                              > >[/color]
                              >
                              >[/color]


                              Comment

                              Working...