static struct{
unsigned a:5;
unsigned b:5;
unsigned c:5;
unsigned d:5;
}v={1,2,3,4};
printf("%d %d %d %d %d",v.a,v.b,v.c,v.d,sizeof(v));
Output is : 1 2 3 4 4
Can someone explain why is the size of this struct 4 ? Shouldn’t it be 16 ?
You’re using 20 bits which fit nicely in 4 bytes. No need for 16 bytes.
EDIT
I think it is actually required that they be packed like that: