I have an array of structures defined as below:
struct {
int x;
char y;
} arr[10];
The size of int on my machine is 4 bytes and a char is of 1 byte. I know the structures would be padded internally i.e each element of array will have a size of 8 bytes. But i want to know whether
1) This is because of the alignment requirement of the int-type member in the next array element or
2) Is it because each structure should itself be aligned on a 8-byte boundary because of the requirement of natural alignment on a structure type variable.
To make my point more clear what should be starting address of the first member of array? If it's an 8 byte aligned address as pointed out in the second case, this may be a problem while defining large 2-D arrays like:
int arr[1000][1000];
Here each element of the 2-D array (i.e each 1-D array) should be aligned on a 4000 byte boundary. The machine may not have memory hole to fulfill this memory requirement.