Union with bits ?

Rene Zwanenburg renezwanenburg at gmail.com
Wed Jun 14 08:51:19 UTC 2023


On Wednesday, 14 June 2023 at 00:59:30 UTC, Paul wrote:
> I would like to have labeled bits in a union with a ubyte.  
> Something like this:
> ```d
> struct MyStruct {
>     union {
>         ubyte status;
>         bit A, B, C…etc
>     }
> }
> ```
> Is something like this possible?
>
> Thanks

You can do something like this if you don't mind compiling with 
-preview=bitfields:

```d
union {
     ubyte status;
     struct {
         bool A : 1, B : 1, C : 1, D : 1;
     }
}
```


More information about the Digitalmars-d-learn mailing list