A typical use of bitfield is to declare a space efficient variable smaller than 8 bits. What i don't understand is the value of declaring those bits as short, int , long , bool etc. For example
typedef struct{
int first:3,
short second:3,
char third:3
} somestruct;
In above case, all 3 variables, i.e. first, second and third are 3 bit long. What is the value of declaring the variable first as int, second as short and third as char?
Or, why is even a data type required? I should be able to declare the above as
typedef struct{
first:3,
second:3,
third:3
} modifiedstruct;
The modifiedstruct assumes no datatype for the variables first, second and third. The responsibility of interpreting the 3 bits as character, numeric or floating should be responsibility of something else.
Both gcc and g++ on linux allow the above behavior.