second draft: add Bitfields to D

Jonathan M Davis newsgroup.d at jmdavisprog.com
Mon Apr 29 15:37:52 UTC 2024


On Monday, April 29, 2024 12:44:08 AM MDT Walter Bright via dip.development 
wrote:
> An enum is distinguished by it not being possible to use .offsetof with it.

I don't think that I have _ever_ seen anyone use offsetof to determine
anything with type introspection other than the actual offset. Existing code
will almost certainly be using & to determine whether a member is an enum or
not.

That being said, _usually_, it's the case that code cares when a member is
an enum or not when doing type introspection, because it's looking for
something else (e.g. for whether the member is a static member variable), so
I don't know whether suddenly having additional members that cannot have
their address taken will break anything, but any situation where there isn't
a trait that outright tells you what you're looking for makes it highly
likely that any existing code which needed to figure it out did so by trying
out a variety of checks and found some combination of things to check for
being true and some combination of things to check for being false and then
did enough testing to be reasonably sure that that combination of checks
told them what they needed to know, but even if they did get it right,
because it's quite indirect, adding more catogories of things which could
affect introspection will ultimately run a pretty high risk of breaking
_something_.

There's only so much that we can do about that, but I do think that we need
to be very careful about saying that X is the way to test for something and
have any expectation that that's how folks are actually doing it unless that
something is a specific trait from __traits or std.traits which checks for
that exact thing.

- Jonathan M Davis





More information about the dip.development mailing list