Hi, I am curious to know if there is a way that one could create a bitfield using the standard technique of creating a structure within a union, as follows:
Code:
typedef union {
struct {
unsigned b0 : 1;
unsigned b1 : 1;
:
:
unsigned b(n-1) : 1;
} bits;
unsigned int value;
} BIT_FIELD_TYPE;
Except, what I'd like to do is to replace all the single-bit elements in the bits structure with a single statement that creates an array of, say, 32 values. The clear advantage of this is that it could be traversed using an iterator, ...
Code:
main() {
BIT_FIELD_TYPE foo;
unsigned int i;
...
for (i = 0; i < n; i++) {
... (print out foo.bits.b[i]) ...
}
So far, I've not figured out a way to do it, either as an array, or using a pointer to iterate through the individual bits.
I'd love to hear if anyone has a solution to this - or even just comments telling me I'm nuts.
Thanks.