Re: Union with bits ?

2023-06-14 Thread Paul via Digitalmars-d-learn
On Wednesday, 14 June 2023 at 22:44:41 UTC, Ali Çehreli wrote: By the way, the string that bitfields() generates can be visualized by simply printing it: const code = bitfields!( ubyte, "A", 1, ubyte, "B", 1, ubyte, "C", 1, ubyte,

Re: Union with bits ?

2023-06-14 Thread Ali Çehreli via Digitalmars-d-learn
On 6/14/23 15:04, Paul wrote: > Question: Why do you say "may be slower than necessary"? Do you mean > compile or runtime or both? Definitely at compile time because the string that gets mixed-in first needs to be generated from your specification. For that, the bitfields() function must be

Re: Union with bits ?

2023-06-14 Thread Paul via Digitalmars-d-learn
On Wednesday, 14 June 2023 at 14:43:58 UTC, Ali Çehreli wrote: D's string mixin syntax may not be the best, the implementation may be slower than necessary, and the concept may be strange (not macros but very similar) but I still find phobos's bifields to be brilliant.

Re: Union with bits ?

2023-06-14 Thread Ali Çehreli via Digitalmars-d-learn
On 6/13/23 17:59, 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? &g

Re: Union with bits ?

2023-06-14 Thread Adam D Ruppe via Digitalmars-d-learn
On Wednesday, 14 June 2023 at 08:51:19 UTC, Rene Zwanenburg wrote: You can do something like this if you don't mind compiling with -preview=bitfields: That doesn't do what you think it does. There's no guarantee the bits will actually line up with the status byte. The best way to do what

Re: Union with bits ?

2023-06-14 Thread Rene Zwanenburg via Digitalmars-d-learn
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

Union with bits ?

2023-06-13 Thread Paul via Digitalmars-d-learn
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