Bitfield structs and suggestion

Daniel Keep daniel.keep.lists at gmail.com
Thu Nov 22 20:32:34 PST 2007


D originally had a 'bit' type in place of 'bool' which could be packed
in structs.  However, people didn't think very much of it, and fairly
loudly complained that they wanted a "real" bool type.  Hence, 'bit' is
now aliased to 'bool'.

The other problem was that 'bit' introduced various problems.  For
instance, you can take the address of anything *except* a bitfield,
since addresses only have byte-level granularity.  Bitfields also cannot
have sensible sizeof properties, which could break generic code.

Off the top of my head, maybe it would suffice to give types a special
'bits' slice type.

int some_float;
int negative = some_float.bits[0..1];
int exponent = some_float.bits[1..9];
int mantissa = some_float.bits[9..$];

Basically just tarting up manual shifts and masking.  Just a thought :)

	-- Daniel



More information about the Digitalmars-d mailing list