bit-level logic operations on enums
FG
home at fgda.pl
Fri Mar 1 05:38:53 PST 2013
On 2013-03-01 13:56, d coder wrote:
> Currently DMD allows me to bit-or two enum variables, but not bit-and. For
> example in the following code, DMD is OK with line 6, but gives an error
> for line 9. I do not see any logic why DMD does that. Is it a bug or is it
> intended.
Strange. | and ^ work but & fails. The promotion from byte to int is unnecessary
in any of those 3 ops. It works correctly for non-enums:
byte x, y, z = 1;
z = x | y; z = x ^ y; z = x & y; z = x >> y; // all OK
z = x << y; z = x + y; z = x * y; z = x / y; // can't convert int to byte
Not sure why byte enum would be handled any differently than simple byte.
More information about the Digitalmars-d
mailing list