[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Mr.Tickle

10/11/2003 10:08:00 AM

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.



16 Answers

Stoyan Damov

10/13/2003 10:42:00 AM

0

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:%23Rx7p79jDHA.3312@tk2msftngp13.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 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.
>
>
>


Mr.Tickle

10/13/2003 2:58:00 PM

0

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.bg> wrote in message
news:eN1tbaXkDHA.2364@TK2MSFTNGP11.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 (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:%23Rx7p79jDHA.3312@tk2msftngp13.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 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

10/13/2003 2:59:00 PM

0

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:ubWKWnZkDHA.424@TK2MSFTNGP10.phx.gbl...
> 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.bg> wrote in message
> news:eN1tbaXkDHA.2364@TK2MSFTNGP11.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 (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:%23Rx7p79jDHA.3312@tk2msftngp13.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
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.
> > >
> > >
> > >
> >
> >
>
>


Mr.Tickle

10/13/2003 4:19:00 PM

0

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.bg> wrote in message
news:e8eC#pZkDHA.2268@TK2MSFTNGP12.phx.gbl...
> 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:ubWKWnZkDHA.424@TK2MSFTNGP10.phx.gbl...
> > 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.bg> wrote in message
> > news:eN1tbaXkDHA.2364@TK2MSFTNGP11.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
(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:%23Rx7p79jDHA.3312@tk2msftngp13.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
> 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.
> > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>


Eric Gunnerson [MS]

10/13/2003 10:36:00 PM

0

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....
Eric's blog is at http://blogs.gotdotnet.c...

This posting is provided "AS IS" with no warranties, and confers no rights.
"Mr.Tickle" <MrTickle@mrmen.com> wrote in message
news:%23Rx7p79jDHA.3312@tk2msftngp13.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 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.
>
>
>


Mr.Tickle

10/14/2003 6:35:00 AM

0

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:OBZgZpdkDHA.2444@TK2MSFTNGP09.phx.gbl...
> 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....
> Eric's blog is at http://blogs.gotdotnet.c...
>
> This posting is provided "AS IS" with no warranties, and confers no
rights.
> "Mr.Tickle" <MrTickle@mrmen.com> wrote in message
> news:%23Rx7p79jDHA.3312@tk2msftngp13.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 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.
> >
> >
> >
>
>


ozbear

10/14/2003 9:55:00 AM

0

On Tue, 14 Oct 2003 08:35:03 +0200, "Mr.Tickle" <MrTickle@mrmen.com>
wrote:

>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:OBZgZpdkDHA.2444@TK2MSFTNGP09.phx.gbl...
>> 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....
>> Eric's blog is at http://blogs.gotdotnet.c...
>>
>> This posting is provided "AS IS" with no warranties, and confers no
>rights.
>> "Mr.Tickle" <MrTickle@mrmen.com> wrote in message
>> news:%23Rx7p79jDHA.3312@tk2msftngp13.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 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.
>> >
>> >
>> >
>>
>>
>
>

Idiot

ozbear

10/14/2003 9:56:00 AM

0

On Mon, 13 Oct 2003 18:18:39 +0200, "Mr.Tickle" <MrTickle@mrmen.com>
wrote:

>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.bg> wrote in message
>news:e8eC#pZkDHA.2268@TK2MSFTNGP12.phx.gbl...
>> 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:ubWKWnZkDHA.424@TK2MSFTNGP10.phx.gbl...
>> > 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.bg> wrote in message
>> > news:eN1tbaXkDHA.2364@TK2MSFTNGP11.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
>(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:%23Rx7p79jDHA.3312@tk2msftngp13.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
>> 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.
>> > > >
>> > > >
>> > > >
>> > >
>> > >
>> >
>> >
>>
>>
>
>

Idiot

ozbear

10/14/2003 10:01:00 AM

0

On Mon, 13 Oct 2003 15:35:46 -0700, "Eric Gunnerson [MS]"
<ericgu@online.microsoft.com> wrote:

>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
>

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

Mr.Tickle

10/14/2003 10:05:00 AM

0

yankstain

"ozbear" <ozbear@no.bigpond.spam.com> wrote in message
news:3f8bc8cc.191775406@news-server...
> On Mon, 13 Oct 2003 18:18:39 +0200, "Mr.Tickle" <MrTickle@mrmen.com>
> wrote:
>
> >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.bg> wrote in message
> >news:e8eC#pZkDHA.2268@TK2MSFTNGP12.phx.gbl...
> >> 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:ubWKWnZkDHA.424@TK2MSFTNGP10.phx.gbl...
> >> > 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.bg> wrote in message
> >> > news:eN1tbaXkDHA.2364@TK2MSFTNGP11.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
> >(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:%23Rx7p79jDHA.3312@tk2msftngp13.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
> >> 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.
> >> > > >
> >> > > >
> >> > > >
> >> > >
> >> > >
> >> >
> >> >
> >>
> >>
> >
> >
>
> Idiot