I hacked bit fields onto Joe Groff's excellent new structs. This
wasn't hard to do, since Joe's code was so well-structured. My draft
code is in the main repository, in the bitfields branch. The current
implementation has really inefficient getters and setters, and I'll
have to change this before it gets merged.
With this change, a struct using bitfields can look like this:
STRUCT: foo
{ a uint bits: 12 }
{ b int bits: 2 }
{ c char } ;
The size of this struct is three bytes, because the a and b slots are
packed right next to each other. The a slot can store integers between
0 and 4095, and the b slot can store integers between -2 and 1. The
choice of 'int' and 'uint' as the types given was arbitrary, and based
on the syntax in C. I could have also gone with 'signed' and
'unsigned' or something like that; I'm not sure what's preferable.
>From what I've read about bitfields, they have an unspecified layout
in C. I wasn't sure where to find documentation for different
platforms, so I went for something arbitrary (they're packed in
textual order, little endian). If anyone can tell me what
convention(s) it should actually use, I'll update the code.
This is the second time I've implemented bitfields in Factor. I hope
this implementation is more useful than my last one.
Dan
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk