bit-level logic operations on enums

d coder dlang.coder at gmail.com
Fri Mar 1 04:56:21 PST 2013


Greetings

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.

BTW if I declare all a,b,c and d as "enum BING_e", then DMD gives errors
for both line 6 and 9.

Regards
- Puneet


enum BING_e: byte {NONE_BING = 0b00, FOO_BING = 0b01, // 1
    BAR_BING = 0b10, BOTH_BING = 0b11}                // 2
void main() {                                         // 3
  BING_e a = BING_e.FOO_BING;                         // 4
  BING_e b = BING_e.BAR_BING;                         // 5
  BING_e c = a | b;                                   // 6
  import std.stdio;                                   // 7
  writeln(c);                                         // 8
  BING_e d = a & b;                                   // 9
  import std.stdio;                                   // 10
  writeln(d);                                         // 11
}                                                     // 12
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130301/63ea7195/attachment.html>


More information about the Digitalmars-d mailing list