February 25, 2005
On Fri, 25 Feb 2005 11:44:41 +1300, <brad@domain.invalid> wrote:

> Anders F Björklund wrote:
>
>> In D logic, the bit fields are obsolete - but bit[] are neat...
>>  http://www.digitalmars.com/d/overview.html:
>>
>>> #  Bit fields of arbitrary size.
>>>    Bit fields are a complex, inefficient feature rarely used.
>>
>>> Bit type
>>> The fundamental data type is the bit, and D has a bit data type.
>>> This is most useful in creating arrays of bits:
>>>
>>>     bit[] foo;
>>   Then it goes on to assign those arrays in multiples of 32 bits...
>>   I'd stay clear of both ;-) (you can use bitshifting and masking?)
>>  --anders
>
> :) Yeah, I'd had a play with bit fields and noticed that they weren't the correct size.  Using shifting and masking is no real issue (and is what the compiler has to do behind the scenes anyhow).
> And infact, I have just found that you can quite nicely hide the bit packing with the use of properties to access packed data :)
>
> Brad

I found bit arrays very useful when dealing with some things... I started one program with
# union bitint
# {
#     uint asInt;
#     bit[uint.sizeof] asBits;
# }

Rather more convenient than messing about with masking, oring/anding etc. In fact, might it not be a useful things to add 'asBits' as a standard property to built in integer types, since they're the ones that get bit-twiddled?



-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
February 25, 2005
Alex Stevenson wrote:

> I found bit arrays very useful when dealing with some things... I started  one program with
> # union bitint
> # {
> #     uint asInt;
> #     bit[uint.sizeof] asBits;
> # }
> 
> Rather more convenient than messing about with masking, oring/anding etc.  In fact, might it not be a useful things to add 'asBits' as a standard  property to built in integer types, since they're the ones that get  bit-twiddled?

You can't use unions, though, since that'll only work for
int and long since D rounds bit[] up to 32-bit boundaries...

(but you could use a (bit*) pointing at the byte, for instance,
so such an "asBits" feature would still be doable I suppose)

So it does have it's uses, but it's still a doubtful feature.
Especially for speed freaks, as pointed out in the sieve tests ?

--anders
Next ›   Last »
1 2
Top | Discussion index | About this forum | D home