This is about ANSI-C (C90). This is what I know:
- I can directly tell the compiler how many bits I want for a specific variable.
- If I want 1 bit which can have the values zero or one.
- or 2 bits for the values 0,1,2,3, and so on...;
I'm familiar with the syntax.
I have problem concerning bitfields:
- I want to define a SET structure.
- It can have maximum 1024 elements (it can have less, but the maximum is 1024 elements).
- The domain of the set is from 1 to 1024. So an element could have any value 1-1024.
I'm trying to create a structure for a SET, and it must be efficient as possible for the memory part.
I tried:
typedef struct set
{
unsigned int var: 1;
} SET;
//now define an array of SETS
SET array_of_sets[MAX_SIZE] //didn't define MAX_SIZE, but no more than 1024 elements in each set.
I know this isn't efficient; maybe it's even not good for what I want. That's why I'm looking for help.