J
junky_fellow
Can somebody please tell me about the structure alignment rules ?
What I found was that on my system (cygwin running on PC, size of
int=4 sizeof long=4, size of long long = 8) the cygwin compiler put
the padding after the last member of structure.
For eg, struct test {
int i;
char c; /* no padding required between
int and char */
/* 3 byte padding is inserted here, Why ?
*/
}
When I print the size of above structure, it gives 8. I am not able to
understand why the 3 byte padding is done after char ?
Why the size of struct is made 4 byte aligned ?
Moreover, if I replace "int" by "long long", the size is 16. So, its
not always 4 byte aligned.
What is the rule, to find out how much padding will be added at the
end of structure ?
What is the byte alignment restriction for a structure ?
thanks a lot for any help ...
What I found was that on my system (cygwin running on PC, size of
int=4 sizeof long=4, size of long long = 8) the cygwin compiler put
the padding after the last member of structure.
For eg, struct test {
int i;
char c; /* no padding required between
int and char */
/* 3 byte padding is inserted here, Why ?
*/
}
When I print the size of above structure, it gives 8. I am not able to
understand why the 3 byte padding is done after char ?
Why the size of struct is made 4 byte aligned ?
Moreover, if I replace "int" by "long long", the size is 16. So, its
not always 4 byte aligned.
What is the rule, to find out how much padding will be added at the
end of structure ?
What is the byte alignment restriction for a structure ?
thanks a lot for any help ...