On Monday, 9 November 2026 at 23:58:19 UTC, Anonymous wrote:
Any adivce before I go down the rabbit hole?

I would consider using a basic integer for the bit packing, and adding getter methods to access it as the 2 different types like the union fields would.

```D
struct Node {
  ubyte  Type_storage: 5;
  bool   Is_Frob: 1;
  byte   Frob_Direction: 2;

  int  Regular_Field;
  /* more regular fields */

  Node_Type    Type()    const => *cast(Node_Type*) &Type_storage;
  Node_Type_Id Type_Id() const => cast(Node_Type_Id) Type_storage;
}
```

Because of D's property syntax you can call `Node.Type` or `Node.Type_Id` without parens just like the union field access, and in optimized builds the generated code will be just as fast.

  • Bitfields Anonymous via Digitalmars-d-learn
    • Re: Bitfiel... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
      • Re: Bit... Anonymous via Digitalmars-d-learn
        • Re:... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
        • Re:... monkyyy via Digitalmars-d-learn
        • Re:... Dennis via Digitalmars-d-learn
          • ... Anonymous via Digitalmars-d-learn

Reply via email to