Hello!

Since I guess there's no enumeration method for creating bit mask constants, I have created a macro:

Code:
```#define BM_ENUM(x)					\
x##_ENUM_IDX,					\
x = 1 << x##_ENUM_IDX,				\
x##_ENUM_IDX_AGAIN = x##_ENUM_IDX

BM_ENUM(FIRST),
BM_ENUM(SECOND),
BM_ENUM(THIRD),
BM_ENUM(FOURTH)
};```
What do you think of it? I don't understand why there wasn't a bit mask enumeration method built in to the language from the beginning, it could have been useful.

2. enum's can be used as bitmasks. Yours is (apparently) trying to do both the bitnumber enumeration and the bitvalues in the same enum, which is a bit odd, but that's obviously your choice (there's no "law" agains repeating the same enum value - although the debugger will show the first one to match, which may not be what you expected).

Since enum values can be declared as you wish, there's really no need to have a special variant that does enum's for bitmasks. There are some languages that attempt to be "swiss army knifes", but C is a rather spartan language, and as long as the constructs can be used to do what you want, then I don't see why there should be another way of doing the same thing.

--
Mats

3. That code is extremely confusing.
I don't see what's so hard about writing this:
Code:
```enum TestBitmask {
First  = 0x01,
Second = 0x02,
Third  = 0x04,
Fourth = 0x08,
Fifth  = 0x10,
Sixth  = 0x20
...
};```
At least then you can look at the code to see what value matches with which enum name, rather than doing some crazy calculation in your head... It's just simple Hex.

4. Theoretically, you could just do
Code:
```enum TestBitmask {
First  = 1,
Second = 1 << 1,
Third  = 1 << 2,
Fourth = 1 << 3,
Fifth  = 1 << 4,
Sixth  = 1 << 5
...
};```
Again, no confusion. And you don't have to calculate hex either if you absolutely don't want to.

5. Originally Posted by TriKri
What do you think of it? I don't understand why there wasn't a bit mask enumeration method built in to the language from the beginning, it could have been useful.
1. It defeats the purpose of enum. An enumeration is a way to give names to the valid values. Yet by combining masks, you get a value that is not equal to any value in the enumeration. A person might therefore assume that the resulting combination is not a valid value. Don't try to trick yourself. A bitwise combination is an integer, not an enum.

2. It only works in C. C++ rejects this kind of thing.

Just do what the rest of the world does. #define your mask constants.