Inline aggregate types
Ethan Watson via Digitalmars-d
digitalmars-d at puremagic.com
Thu Dec 1 13:04:07 PST 2016
On Thursday, 1 December 2016 at 20:57:13 UTC, Andrei Alexandrescu
wrote:
> The simplest way to go here is to accept an initializer for the
> entire ubyte/ushort/uint/ulong underlying the bitfields. --
> Andrei
In terms of efficiency at compile time, indeed. But there's
multiple paths there. You could assign to the value directly,
which would require intimate knowledge of how the implementation
works. Which then means you'd need a helper.
Under the hood for my implementation, in fact, it makes that
single initializer for the bitfield. I'm currently storing in a
ubyte array that stores in multiples of 4 bytes, and as a part of
parsing the defined struct it also creates an initializer for
that array. I'll have to do a bit more work so that I can also
specify the underlying storage type or intelligently work it out
(the example I used here, in fact, would only ever want one byte
of storage to match C++ built-in bitfields exactly unless I'm
mistaken).
More information about the Digitalmars-d
mailing list