J
junky_fellow
Many times the compiler does the padding between two variables
in a structure. For eg. if I have the structure as follows:
struct sample {
int var1;
char var2;
<--- padding of three bytes here
int var3;
}
Why the compiler allocates 3 extra bytes between var2 and var3 ?
I read some articles that say, the compiler always allocates
the address to the variable which is a multiple of the size of
the variable.
for eg. if size of int is 4, the address allocated will always be a
multiple of 4. Why is it so. If the processor can read a
character from any address then why cannot an integer ?
Does all compliers written for a particular architecture generate
the same padding or allocate same space for a particular structure ?
in a structure. For eg. if I have the structure as follows:
struct sample {
int var1;
char var2;
<--- padding of three bytes here
int var3;
}
Why the compiler allocates 3 extra bytes between var2 and var3 ?
I read some articles that say, the compiler always allocates
the address to the variable which is a multiple of the size of
the variable.
for eg. if size of int is 4, the address allocated will always be a
multiple of 4. Why is it so. If the processor can read a
character from any address then why cannot an integer ?
Does all compliers written for a particular architecture generate
the same padding or allocate same space for a particular structure ?