Why are std.bitmanip.bitfields so big ?

wjoe invalid at example.com
Mon Jul 27 09:49:19 UTC 2020


 From the API documentation:

> Create a bitfield pack of eight bits, which fit in one ubyte.
> [...]
>
> struct A
> {
>     mixin(bitfields!(
>        bool, "flag1",    1,
>        bool, "flag2",    1,
>        uint, "",         6));
> }
> 
> A a;
> writeln(a.flag1); // 0
> a.flag1 = 1;
> writeln(a.flag1); // 1
> a.flag1 = 0;
> writeln(a.flag1); // 0
> writeln(a.sizeof);


> Application output
>
> false
> true
> false
> 16

I would expect a sizeof 1. Why is its size 16 ?

Source: https://dlang.org/library/std/bitmanip/bitfields.html


More information about the Digitalmars-d-learn mailing list