proper bit fields in the D2 language?
Daniel Keep
daniel.keep.lists at gmail.com
Tue Apr 21 23:14:44 PDT 2009
nobody wrote:
> == Quote from Brad Roberts (braddr at puremagic.com)'s article
>> The auto-generated code from the library is the same code the compiler
>> would end up generating. You can test that theory by comparing the
>> produced assembly for a C vs a D implementation.
>
> If the generated code are same, and it's in the std library, which means no
> difference in the backend.
>
> Then I'd rather write:
>
> struct A
> {
> bool flag1: 1;
> bool flag2: 1;
> // uint "", 6; // this should be auto-magically generated by the compiler
> }
>
> (the code is more clear, and the compiler can give better message).
>
> than this:
>
> struct A
> {
> mixin(bitfields!(
> bool, "flag1", 1,
> bool, "flag2", 1,
> uint, "", 6));
> }
Except that bitfields don't appear to be a widely used feature. If you
can put it in the library with no performance penalty AND simplify the
compiler at the same time, that looks like a good thing to me, and I
believe Walter agrees.
-- Daniel
More information about the Digitalmars-d
mailing list