[chirp_devel] cant use structs with bit type members totalling less than 8 bits
Dan Smith
Sun Feb 23 18:05:04 PST 2014
> But when I do this bitwise.py croaks with "bit array must be divisible
> by 8." (trace below).
>
> Why is it this way? The second form would be much simpler and cleaner
> overall in the code to work with.
Because everything is bytes underneath? I'm not sure how to explain it,
but if you look at bitwise, everything has to map to a byte and an
offset at some point. The bit array maps to a whole byte, which is why
it has to be eight elements long.
> Is there some alignment concern? Is there any provision for a data type
> of less than a byte?
It gets really complicated if you try to support something like this
(which is equivalent to what you're asking for):
struct {
bit a;
u8 b;
bit c;
u24 d;
} foo;
In the above, b is eight bits that span a byte. c is in the third byte
and d ends in the seventh byte with some bits left over. Implementation
complexity aside, supporting the above also means it becomes very
difficult to realize that there are some unaddressed bits left over at
the end of foo, and it's difficult to know the address where the thing
that comes after foo starts, especially if you think you've created
something that is a whole number of bytes.
So, complexity of supporting the unaligned accesses, and the complexity
of validating something by looking at it led me to write it such that
everything had to be aligned to byte boundaries. For most cases, this is
really not a problem, and I don't think the few cases that suffer are
worth the additional complexity. It's pretty easy to just define a few
helper methods to make things easier to understand, IMHO.
--Dan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: OpenPGP digital signature
Url : http://intrepid.danplanet.com/pipermail/chirp_devel/attachments/20140223/a2f8dcb4/attachment-0001.bin
More information about the chirp_devel
mailing list