S
Stanley Rice
Dear all
Here I declare a structure as follows:
struct flag
{
unsigned int a : 8; /* 1 - 7 is yield the same result*/
char b;
char c;
char d;
};
and sizeof(struct flag) equals 4, which is intuitive.
But when I make a little modification, where the bitwidth allocated to
a is 9:
struct flag
{
unsigned int a : 9; /* modification here */
char b;
char c;
char d;
};
and sizeof(struct flag) equals 8, but not 5, where variable 2 bytes
are allocated to variable a, and 3 bytes are allocated to the
following char type variable.
I want to know how many bytes are allocated to variable a? and how the
padding in the obove structure performs.
Here I declare a structure as follows:
struct flag
{
unsigned int a : 8; /* 1 - 7 is yield the same result*/
char b;
char c;
char d;
};
and sizeof(struct flag) equals 4, which is intuitive.
But when I make a little modification, where the bitwidth allocated to
a is 9:
struct flag
{
unsigned int a : 9; /* modification here */
char b;
char c;
char d;
};
and sizeof(struct flag) equals 8, but not 5, where variable 2 bytes
are allocated to variable a, and 3 bytes are allocated to the
following char type variable.
I want to know how many bytes are allocated to variable a? and how the
padding in the obove structure performs.