interfacing C bitfield structs
Anders F Björklund
afb at algonet.se
Mon Mar 20 01:45:59 PST 2006
Walter Bright wrote:
> Add two member functions for each:
>
> bool fBinary() { return BITS & 1; }
> bool fBinary(bool b) { BITS |= b; return b; }
>
> bool fParity() { return (BITS & 2) != 0; }
> bool fParity(bool b) { BITS |= b << 1; return b; }
>
> and then, because functions work like properties, you can use them as if
> they were properties.
You'll need to add some casts, though, for GDC:
"cannot implicitly convert expression (BITS & 1) of type uint to bit"
Or just change it to: return ((BITS & 1) != 0);
--anders
More information about the Digitalmars-d
mailing list