c++ - struct size not as expected when using bit fields -
this question has answer here:
- why isn't sizeof struct equal sum of sizeof of each member? 11 answers
- padding in structures in c 5 answers
with below code:
struct s { unsigned char b1 : 3; int i; };
i can deduce char b1 of 1 byte , using 3 bits of , int 4 bytes when try print out size of s, 8 bytes instead of 5 bytes(1 char+4 int) expected , not understanding obvious. can explain why size of s 8 bytes?
Comments
Post a Comment