i have read more about data misalignment but i still have one more question:
suppose i have the following structure:
char a; // 1 byte
int b; // 4 bytes
short c; // 2 bytes
char d; // 1 byte
and the processor can access 4 bytes of memory at once. if the process tries to access the integer filed b it would be misaligned data so the compiler pads this structure to enforce alignment naturally as follows:
0x0000 char a;
0x0001 char pad0; //this to force data to be aligned.
0x0004 int b;
0x0008 short c;
0x000a char d;
0x000b char pad;
i m still confused how the data are not misaligned after this padding? i mean that if the process tries to access the char field named by d : it should access the memory address 0x0008 then making shifting to get access of address 0x000a,right?
so by this the int b is aligned but the char d is misaligned , but every document i read tells that all the data are aligned?
how could this happen, may b i m still confused what is meant by aligned and misaligned data concepts?
thanks in advance