bitfield_array is an array of structures "value".
When you declare with [] empty size then you tell compiler to reserve just one member of that array something like [1] t.e when you will reference that you have to put index [0].
This array could later be resized by using dynamically memory allocation.
In this particular case bitfield_array[0] will have value in binary code as 1101001000... ( or depend on endianess of the processor - 1000100101...)
as an example if we change declaration of bitfield... as an array with size 2 then you will have to put initialize for two as well otherwise compiler give you warning (not error) that something missing.
struct value bitfield_array[2] = {{ 1, 2, 4, 8 }, {0, 1, 2, 3}};
Question is not clear: what do you mean "apply this code in ...? This code declares array (NUM) of structures (code) that happens to be only unsigned char size (Choose). Because there is initialization at declaration time array NUM has size of 4 structures (equals 4 unsigned chars). First member of array NUM[1].Choose wil have 1, second NUM[2].Choose will have 2 and so on.
Thank again. I understand what you try to explain.
The code declared array of structures. The array size is 4. This 4 values declarated as unsigned char type and store in the code. This 4 values is constant variable.
NUM[0] is use ONE bits
NUM[1] is use TWO bits
NUM[2] is use THREE bits
NUM[3] is use FOUR bits
Total is use 10 bits
My question is I'm would like to apply bit field for my constant variable instead of using unsigned char type 8-bits for each variable. I'm trying to reduce my code size in my processor. Mean that array of NUM[] make use of 2byte instead of using 4byte to store my 4 variables. Is it possible to do that? or Is it got another method to solve this problem?
Thank ya. This few days i try to find out the answer and do some google seach. I don't have idea. Actually i want to call out the number pattern which can do it in BifField form.
1st num = 1
2nd num = 2
3th num = 4
4ft num = 8
But nevermind since it is impossible to do that.
Another question, let say if i have 3 variable which is in BitField form.
the bitfield_array[1] have value in binary code as 100101. Is it possible we can asign the bitfield_array to another variable directly.
ex. Var = bitfield_array; // Var = 37