M
Mr.Tickle
Why would I ask you, when I can ask Jack as Im sure he knows more than you.
If I wanted Jack's opinion I would ask Jack.
If I wanted Jack's opinion I would ask Jack.
NoOne said:You started with "obvious error by the compiler", "Obvious mistake by Eric
Gunnarsson", "should be powers of two". After people pointed out that the
flag attribute is doing exactly what the spec says. You now changed your
tune to "I'm thinking outside the box" and "wouldn't it be handy to
increment of powers of 2". Which indicates you had no idea what the flag
attribute should have been doing to begin with, else you would have started
out the thread with "would be useful to specify an increment of powers of
2".
// Run this code and look for his obvious error by the compiler
namespace FlagCheck
{
using System;
[Flags]
enum SomeFlags
{
None = 0,
One,
Two,
Three,
Four,
Five,
Six,
All = One | Two | Three | Four | Five | Six
}
class Class1
{
[STAThread]
static void Main(string[] args)
{
SomeFlags f;
f = SomeFlags.Four; // Set flag FOUR and ONLY FOUR, get ready for a
supprise
if ( (f & SomeFlags.One) > 0)
{
Console.WriteLine("flag one is set");
}
if ( (f & SomeFlags.Two) > 0)
{
Console.WriteLine("flag two is set");
}
if ( (f & SomeFlags.Three) > 0)
{
Console.WriteLine("flag three is set");
}
if ( (f & SomeFlags.Four) > 0)
{
Console.WriteLine("flag four is set");
}
if ( (f & SomeFlags.Five) > 0)
{
Console.WriteLine("flag five is set");
}
if ( (f & SomeFlags.Six) > 0)
{
Console.WriteLine("flag six is set");
}
Console.ReadLine();
}
}
}
point across is certainly counter productive.
100 said:Some of the flags might have more the one bit set to 1 and thay might be not
power of 2. This doesn't makes them *less flags* than the others, though.
Mr.Tickle said:Thats my point, it should be. There is no reason to have it otherwise.
Logic dictates that it should be powers of 2, nothing else.
Alan Pretre said:Mr.Tickle said:Thats my point, it should be. There is no reason to have it otherwise.
Logic dictates that it should be powers of 2, nothing else.
Using what you propose, what would be the value of b here?
[Flags]
enum Flags {
a = 6,
b
}
Alan Pretre said:Mr.Tickle said:Thats my point, it should be. There is no reason to have it otherwise.
Logic dictates that it should be powers of 2, nothing else.
Using what you propose, what would be the value of b here?
[Flags]
enum Flags {
a = 6,
b
}
Alan Pretre said:Mr.Tickle said:Thats my point, it should be. There is no reason to have it otherwise.
Logic dictates that it should be powers of 2, nothing else.
Using what you propose, what would be the value of b here?
[Flags]
enum Flags {
a = 6,
b
}
Mr.Tickle said:if you need more than one bit set , override the default like i did in the
All = one | blah example. just as normal.
Have you ever seen a bit set to 3 by default?
default behaviour on bitfields should be powers of 2, if you want otherwise
(like enums normally do) override it with a value, then it continues from
there.
Alan Pretre said:That's right, you have to explictly set it. You're arguing about what C#
should do when the enum members are explicitly initialized.
Mr.Tickle said:If its not explicidly set then its setting BY DEFAULT multiple bits. Im
proposing that DEFAULT for UNASSIGNED values are in powers of 2, which would
then be single set bits for UNASSIGNED values.
Mr.Tickle said:Thats my point, it should be. There is no reason to have it otherwise.
Logic dictates that it should be powers of 2, nothing else.