S
syuga2012
Hi Folks,
I came across that structure elements should be aligned on even
boundary or multiples of 4. Does this mean that if a structure has 3
members as follows
struct a
{
char c;
int i;
long t;
};
the int would have to be aligned to a even memory address and the long
to a memory address which is a multiple of 4.
What about the char? Can it be on a even or odd memory address?
What if there was another char in between i and t? Will there be any
padding and will char be on even memory address or odd memory address?
How many bytes padding will be added between i and t. I am really
confused about this whole alignment thing. I did a google but I am
more confused after that! Also does this alignment apply only to
structures or its a general rule. Sorry, If I am sounding silly, but I
am not at peace.Can some one be kind enough to explain me in simple
terms?
Thank you very much for your time. Appreciate it.
syuga
I came across that structure elements should be aligned on even
boundary or multiples of 4. Does this mean that if a structure has 3
members as follows
struct a
{
char c;
int i;
long t;
};
the int would have to be aligned to a even memory address and the long
to a memory address which is a multiple of 4.
What about the char? Can it be on a even or odd memory address?
What if there was another char in between i and t? Will there be any
padding and will char be on even memory address or odd memory address?
How many bytes padding will be added between i and t. I am really
confused about this whole alignment thing. I did a google but I am
more confused after that! Also does this alignment apply only to
structures or its a general rule. Sorry, If I am sounding silly, but I
am not at peace.Can some one be kind enough to explain me in simple
terms?
Thank you very much for your time. Appreciate it.
syuga