I would expect both structs to be 8byte in size , or atleast the same size !
but good_struct turns out to be 8bytes and bad_struct 12 .
what am I doing wrong here ?
thx !
hofrat
///////////////////////////////////////
It's general padding performed everywhere for a 32-bit m/c. Since the short
number is considered to be of 2 bytes whereas new data should start at the
next 32 bit alignment( if the data length exceeds the padding required )
hence next 2 bytes are left as padding, so the actual struct. of your
defined structutres are as follows,
struct{
short x; /* 2- bytes */
/* again 2- bytes padding */
long y; /* 4 - bytes */
short z; /* 2 - bytes */
/* again 2 - bytes padding
}bad_struct;
struct{
long y; /* 4 - bytes */
short x; /* 2 - bytes */
short z; /* 2 - bytes */
}good_struct;
anil
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/