Vladimir said:
I didn't know that. Do you have an example of how it can be useful?
If you have logical subranges in the enumeration constants,
then you often find the equivalent of the above, i.e.
enum foo {
EFooInvalid,
EFooErrStart,
EFooErrBar = EFooErrStart,
....
EFooErrBaz,
EFooErrEnd = EFooErrBaz,
EFooWarnStart,
EFooWarnQux = EFooWarnStart,
....
EFooSuccessStart,
EFooOK = EFooSuccessStart,
EFooFullSuccess,
EFooSuccessEnd = EFooFullSuccess,
EFooMaxReturn = ESuccessEnd,
EFooNumReturnCodes
};
int isFooWarningReturn (enum foo retval)
{
return (EFooWarnStart <= retval)
&& (retval <= EFooWarnEnd);
}
I usually use separate values for the "Ends".
This can make sense for bitranges, too.
E.g.
enum FooOffsets {
EFoStartWobble = 0,
EFoIsRoundWobble = 0,
...
EFoWobbleTypeBit3,
EFoEndWobble,
EFoStartWibble = EFoEndWobble,
EFoIsSquareWibble = EFoStartWibble,
....
EFoEndWibble,
....
};
#define CONCAT(a, b) a##b
#define FOO_MASK(WKind) ((1 << CONCAT(EFoEnd, WKind)) \
- (1 << CONCAT(EFoEnd, WKind)))
These are obviously made-up but should give an impression
of what you can abuse this for
Cheers
Michael