Whats wrong with this C# compiler :D Can you guess the OBVIOUS mistake on Eric Gunnarsson's part.

J

Jason Smith

See how you are? No one wants to help you out. Your mannerisms alone make
you fail to acheive the one thing you want: To convince anyone at all that
you are right about this. The argumentative style is working against you.
The profanity makes you look less than moderately intelligent, and certainly
uncultured. Time to sign up for charm school.
 
J

Jason Smith

Have you actually thought enough inside the box to get anything done?

Tell ya what, why don't you specify a set of rules that will create the
default behavior you are looking for, and also handle the case if the
programmer specifies one of the values to be "b = 6"?

You keep making these arguments and stating how clear it is that this is the
way it should be. Everyone keeps coming back and saying that there is no
set of rules to handle that case, in general. Why don't you explain them?

Mr.Tickle said:
Would it not be useful to be able specify an increment like powers of 2 for
bitfields, or any other increment somehow? Why must it always be one, I know
what the damnn manual says, dont quote me on that crap, I am thinking OUT OF
THE BOX (something which alot of you lot have yet to experience)
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hi Alan,

I think it still would be handly if the compiler would issue a warning that
an enum marked as "[Flags]" has members that haven't been explicitly
initialized and they have been therefore assigned values that are not powers
of 2 due to the increment.
 
F

Frans Bouma

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

You assume the [Flags] attribute makes the values in the enum 1, 2,
4, 8, 16, 32 etc.. This is not always wanted.

Perhaps you have flags which run like this: 1, 2, 3 (1 OR 2), 4, 8
etc.. How would that be determined? In other words: you initial thoughts
of 'it should be a bitfield' are not true because that would be limiting.
However because you can use bitwise operators with enums no matter what,
the attribute is of no use in C# IMHO. Oh, and always write out your
flag's values when you want to use them in OR operations :)

FB
 
J

Jon Skeet [C# MVP]

Frans Bouma said:
Perhaps you have flags which run like this: 1, 2, 3 (1 OR 2), 4, 8
etc.. How would that be determined? In other words: you initial thoughts
of 'it should be a bitfield' are not true because that would be limiting.
However because you can use bitwise operators with enums no matter what,
the attribute is of no use in C# IMHO.

Its use in C# is when you convert a value to a string, the value comes
out as a delimited set of the names. I don't know whether parsing a
that delimited set of names also requires the Flags attribute.
 
B

bwahahahaha

You lost the plot, nobody is discussing of I have never mentioned at all
FORCING powers of 2, I am discussing DEFAULTs for UNASSIGNED values. Go
figure numbnuts.



Frans Bouma said:
// 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
}

You assume the [Flags] attribute makes the values in the enum 1, 2,
4, 8, 16, 32 etc.. This is not always wanted.

Perhaps you have flags which run like this: 1, 2, 3 (1 OR 2), 4, 8
etc.. How would that be determined? In other words: you initial thoughts
of 'it should be a bitfield' are not true because that would be limiting.
However because you can use bitwise operators with enums no matter what,
the attribute is of no use in C# IMHO. Oh, and always write out your
flag's values when you want to use them in OR operations :)

FB
 
B

bwahahahaha

I know what flags are, i dont need youre patronising attempt to gues that I
dont. I am suggesting a default for unassigned values. I belive it should be
safer to have powers of 2 for unassigned values, unless specified otherwise.
It would also be nice for enums in general to be able to override the
default increments from 1, to my own chosing.

Who is discussing forcing values? Not me, you are. I am discussing default
increments that I am able to specify where absent values are in the defined
type.


Frans Bouma said:
// 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
}

You assume the [Flags] attribute makes the values in the enum 1, 2,
4, 8, 16, 32 etc.. This is not always wanted.

Perhaps you have flags which run like this: 1, 2, 3 (1 OR 2), 4, 8
etc.. How would that be determined? In other words: you initial thoughts
of 'it should be a bitfield' are not true because that would be limiting.
However because you can use bitwise operators with enums no matter what,
the attribute is of no use in C# IMHO. Oh, and always write out your
flag's values when you want to use them in OR operations :)

FB
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top