B
bg
Hi,
I would like to know how memory will be aligned for the following
structure containing bit field.
struct bitfld
{
char a: 2;
int b: 2 ;
char c: 2;
} foo;
where char is 1 byte and int is 2 byte data types and 1 byte packing is
used.
I would like to know whether memor will be aligned as
1. Allocate 2 bits for a. Then leave 6 bits(Since next is an int type
bit field).
Allocate 2 bits for b. Then leave 6 bits(Since next is a char type
bit field).
Allocate 2 bits for c.
So altogether 3 bytes will be allocated for structure foo.
OR as
2. Allocate 2 bits for a, 2 bits for b and 2 bits for c. All in the
same byte.
So altogether 1 byte will be allocated for structure foo.
Hoping your reply at the earliest,
Byju
I would like to know how memory will be aligned for the following
structure containing bit field.
struct bitfld
{
char a: 2;
int b: 2 ;
char c: 2;
} foo;
where char is 1 byte and int is 2 byte data types and 1 byte packing is
used.
I would like to know whether memor will be aligned as
1. Allocate 2 bits for a. Then leave 6 bits(Since next is an int type
bit field).
Allocate 2 bits for b. Then leave 6 bits(Since next is a char type
bit field).
Allocate 2 bits for c.
So altogether 3 bytes will be allocated for structure foo.
OR as
2. Allocate 2 bits for a, 2 bits for b and 2 bits for c. All in the
same byte.
So altogether 1 byte will be allocated for structure foo.
Hoping your reply at the earliest,
Byju