Hello to everyone, I want to my ARM7 to access a (const)bitfield array, but as i'am absolute beginner not sure about C-syntax. My textbook don't includes Bitfield-Array. Hope someone takes a look at this:
struct { unsigned char red[32] :1; unsigned char orange[32] :1; unsigned char yellow[32] :1; unsigned char green[32] :1; unsigned char blue[32] :1; unsigned char violett[32] :1; } my_color; const my_color.red[] ={1,0,1,1,1,1,0,0,1,1,1,1,0,1,1,1,1,1,1,1,1,0,1,0,0,1,1,1,1,0,1,1}; const my_color.orange[] ={0,1,0,1,1,1,0,0,1,1,1,1,0,1,0,0,1,1,0,1,1,1,1,1,1,0,1,1,1,0,0,1}; const my_color.yellow[] ={1,0,1,1,1,1,0,0,1,1,1,1,0,1,1,1,1,1,1,1,1,0,1,0,0,1,1,1,1,0,1,1}; const my_color.green[] ={0,1,0,1,1,1,0,0,1,1,1,1,0,1,0,0,1,1,0,1,1,1,1,1,1,0,1,1,1,0,0,1}; const my_color.blue[] ={1,0,1,1,1,1,0,0,1,1,1,1,0,1,1,1,1,1,1,1,1,0,1,0,0,1,1,1,1,0,1,1}; const my_color.violett[]={0,1,0,1,1,1,0,0,1,1,1,1,0,1,0,0,1,1,0,1,1,1,1,1,1,0,1,1,1,0,0,1}; int main (void) { int i; for(i=0;i<32;i++) { printf("%u ",my_color.red[i]); printf("%u ",my_color.orange[i]); printf("%u ",my_color.yellow[i]); printf("%u ",my_color.green[i]); printf("%u ",my_color.blue[i]); printf("%u ",my_color.violett[i]); printf("%u\n",i); } while(1){}
first as i tried some syntax-variations i just got normal errormessages or programms didn't what i expected to do. But suddenly after some time my programm makes CA stop with a WINDOWS errormessage :ca.exe hat Fehler verursacht und wird geschlossen. Starten Sie das Programm neu. Ein Fehlerprotokoll wird erstellt. OK How can i bring my little blinky-toy to the water? :-)
And one byte is not guaranteed to be 8 bits large. Only to be _at least_ 8 bits. If the machine have 36-bit word size (some older IBM mainframes), it may have 9-bit bytes.
There are no required standard for the placement of bit or byte paddings (except that specific operating systems defines byte padding standards for access to OS system calls) and bit-fields may be stored left-aligned, right-aligned or in the middle of an integer.
The bit-fields where not invented for mapping of physical bits in microcontrollers, but for creating small (signed or unsigned) integers for better packing of data when the full numeric range of the native integer sizes wasn't needed.
When using bit fields, it is very important to remembered that two-complement storage means that a 1-bit signed bit field can only store the values -1 and 0. Testing the bit field for the value ==1 is one of the most common errors.
As long as the software doesn't performs binary writes of the bitfields to processor registers, to files or over communication channels, there are no compatibility problems with them.
When fiddling with bits in a microcontroller, the bit operations (& | ~ << >> ^) are normally used instead, since they are portable between compilers.