[chirp_devel] cant use structs with bit type members totalling less than 8 bits
Jens J.
Sat Feb 22 21:11:09 PST 2014
Hi Dan,
So I have a use for a struct with 4 single-bit members.
currently vx3 (And others) have a separate structure that contains some bitmask fields for various flags.
They are only 4 bits per channel. However, due to bitwise constraints, it seems we are left with doing something like:
struct {
u8 odd_flagA:1,
odd_flagB:1,
odd_flagC:1,
odd_flagD:1,
even_flagA:1,
even_flagB:1,
even_flagC:1,
even_flagD:1;
} flags [50];
and then using some unholy trickery to interleave this out where we need it - it's very ugly, and confusing.
What I'd like to do is take advantage of the simple "bit" type in bitwise.
So I thought i'd simplify the above to:
struct {
bit flagA;
bit flagB;
bit flagC;
bit flagD;
} flags [100];
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.
Is there some alignment concern? Is there any provision for a data type of less than a byte?
File "/Users/jens/build/chirp.hg/chirp/vx3.py", line 372, in process_mmap
self._memobj = bitwise.parse(MEM_FORMAT, self._mmap)
File "/Users/jens/build/chirp.hg/chirp/bitwise.py", line 857, in parse
return p.parse(ast)
File "/Users/jens/build/chirp.hg/chirp/bitwise.py", line 850, in parse
self.parse_block(lang)
File "/Users/jens/build/chirp.hg/chirp/bitwise.py", line 841, in parse_block
self.parse_struct(d)
File "/Users/jens/build/chirp.hg/chirp/bitwise.py", line 822, in parse_struct
return self.parse_struct_decl(struct[0][1])
File "/Users/jens/build/chirp.hg/chirp/bitwise.py", line 805, in parse_struct_decl
self.parse_block(block)
File "/Users/jens/build/chirp.hg/chirp/bitwise.py", line 843, in parse_block
self.parse_defn(d)
File "/Users/jens/build/chirp.hg/chirp/bitwise.py", line 773, in parse_defn
gen = self.do_bitarray(i, count)
File "/Users/jens/build/chirp.hg/chirp/bitwise.py", line 745, in do_bitarray
raise ValueError("bit array must be divisible by 8.")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://intrepid.danplanet.com/pipermail/chirp_devel/attachments/20140222/ee3bf377/attachment-0001.html
More information about the chirp_devel
mailing list