March 20th, 2013, 04:47 AM
-
Bit fields
the foll code when run on gcc compiler gave 12 as output
Code:
struct aa{char a:3;int b:30;char c:3;}; printf("%d",sizeof(struct aa));
but since sizeof int is 4 and char is 1 then why does it give 12 instead of 8 as output????
March 20th, 2013, 06:44 AM
-
it because of structure padding.
compiler use memory in the pack of 4 bytes.
thats why its giving u output as 12 byte.
to get 6 byte as output use
so compiler will not use structure padding.
March 20th, 2013, 10:07 AM
-
Originally Posted by eramit2010
to get 6 byte as output use
I think it should be 5 not six 4 for int and 1 for char
March 20th, 2013, 02:26 PM
-