arbitrary bitsize of variables

Anders F Björklund afb at algonet.se
Sun Sep 30 01:13:31 PDT 2007


Daniel Keep wrote:

> dominik wrote:

>> Thanks guys, too bad bitfields are not supported - is there a special reason 
>> why bitfields are not supported? I know there is a danger with them for 
>> direct bitwise manipulation, but I find them very useful, and necessary - 
>> since I'm doing alot of direct manipulation on arbitrary bitfield size types 
>> (imaging and cryptography).

> Basically, we used to have a 'bit' type which had two literals: true and
> false.  The problem was that bits were different from every other type
> in that you couldn't reliably take the address of one.  Things like a
> bit field's offsetof property wouldn't make sense at times.

The bit type wasn't very usable for bitfields either, since it would
align to a 32-bit boundary and worked differently between platforms...
It also had some strange non-integer properties, so it was better
for everyone involved when it just assumed the bool type name again.

The D programming language overview instead had this to say:
    "Bit fields of arbitrary size.
     Bit fields are a complex, inefficient feature rarely used."
http://www.digitalmars.com/d/1.0/overview.html "Features To Drop"

So one needs to wrap the bitfields in bigger types and do the shifting
oneself, as was shown by previous posters. Tedious, but not very hard ?

--anders


More information about the Digitalmars-d-learn mailing list