Extending bitfields to enumerations of any enumerator type

Walter Bright newshound2 at digitalmars.com
Sat Oct 11 03:16:51 UTC 2025


On 10/8/2025 2:39 PM, Timon Gehr wrote:
> I.e., you can't really be sure that an `enum` type variable holds one of the 
> blessed values.
> 
> I am not particularly fond of this design.

Now that we have bit fields, you could write:

```d
struct Bits { union { int all; struct { int bit0:1, bit1:1, bit2:1; } } }

Bits b;
b.bit0 = 1;
b.bit1 = 1;
b.bit2 = 1;
b.all = 0;
```

which is what I'd like to do with the dmd source code, but alas the bootstrap 
compiler is too old.


More information about the Digitalmars-d mailing list