I believe the best way to do this is not with bit-fields. It is with a mask and functions. Do this:
Code:
char getBit(unsigned char byte, char pos) //pos {1,8}
{
switch(pos)
{
case 1:
return byte & 1; // 00000001
case 2:
return byte & 2; // 00000010
...
case 8:
return byte & 128; // 10000000
}
}
void setBit(unsigned char* byte, char bit, char pos) //bit = 0 or 1, pos {1,8}
{
if (bit == 0)
switch(pos)
{
case 1:
*byte &= 254; // 11111110
...
case 8:
...
}
else if (bit == 1)
switch(pos)
{
case 1:
*byte |= 1; // 00000001
...
case 8:
...
}
}
or sth like that. So you use an unsigned char as a byte and just access each bit with bit operators. What you do is also possible, but again, you would need to copy each time the value of byte to bits and vice versa if you want to use a struct.
edit: I would guess that you cannot actually access 1 bit, so each bit will take 1 byte int the memory. So there is no reason to use bit fields if you also want to use the byte as whole. If the struct is actually 2 bytes in total (1 for byte, 1 for bits) then you MIGHT be able to have only the bits and cast the struct to an unsigned char, though don't think something like this will work.