The data is laid out inside the struct in the same order it was defined.
Whether there is any PADDING between its member fields or not depends on the datatypes involved. I believe the default behaviour is that all fields are aligned to 16 byte boundaries, and so therefore the entire struct always ends on a 16 byte boundary too.
That means that single CHAR member will be followed by one byte of padding, but SHORT or LONG members don't need any padding at all.


So if I had this struct:

struct some_name
{
    int a;
    int b;
    int c;
}


And I was given a memory address to the struct, let's say this address is x, the address for each member would look like this?

member a's address is x
member b's address is x+2
member c's address is x+4

right? Seems like a struct is just a fancy array...
Posted on 2009-06-08 13:48:13 by ITAmember
In non-ancient 32-bit compilers, int is 32-bit.
A struct is far from being just an array:

struct sss{
double a; // 0
char b; // 8
float c; // 12
short d[7]; // 16
int e; // 32
__m128 f; // 48
char g; // 64
}; // sizeof(sss) = 80

Packing modifies this behavior.
Posted on 2009-06-08 17:48:07 by Ultrano
Thank you. :D
Posted on 2009-06-09 15:10:34 by ITAmember