Upcoming bitfield and adam's call to make it even better

Quirin Schroll qs.il.paperinik at gmail.com
Thu Oct 20 12:42:53 UTC 2022


On Tuesday, 18 October 2022 at 19:11:35 UTC, ryuukk_ wrote:
> Here is the link of Adam's blog post: 
> http://dpldocs.info/this-week-in-d/Blog.Posted_2022_09_12.html#d-bitfields-could-be-good

The syntax Adam proposes is this:
```d
ulong fields {
       msb : 1,
       _reserved: 62,
       lsb: 1,
};
```

Personally, I don’t like the idea of taking the syntax `Type 
Identifier { }` for something as niche as bit fields. If we ever 
move to properties à la C#, this will close a door. And it will 
close it unnecessarily. The fix is rather easy: Remove the name:

```d
ulong
{
     msb: 1; // semi colon
     _reserved: auto; // auto (allowed at most once) = ulong’s 
bits minus given bits.
     lsb: 1;
} // no semi colon
```

It still should have a auto-generated name for the allMembers 
trait. If *you* want a name, use an anonymous union:

```d
union
{
     ulong bitfields;
     ulong
     {
         msb: 1;
         _reserved: auto;
         lsb: 1;
     }
}
```


More information about the Digitalmars-d mailing list