lkml.org 
[lkml]   [2001]   [Jun]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRE: sizeof problem in kernel modules
Date
struct { short x; long y; short z; }bad_struct;
struct { long y; short x; short z; }good_struct;

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/

\
 
 \ /
  Last update: 2005-03-22 12:55    [W:0.093 / U:2.052 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site