主题:请高手给我指点一下sizeof()的原理
我定义了两个结构体,成员都一样,但是顺序不一样。用sizeof()函数看一下他们的大小,竟然发现不一样,一个是32,一个是28!!
struct s1 {
int ra;
int dec;
bool tag;
char catalog;
short rmag;
short bmag;
short jmag;
short hmag;
short kmag;
long pm_ra;
long pm_dec;
};
struct s2 {
int ra;
int dec;
short rmag;
short bmag;
short jmag;
short hmag;
short kmag;
long pm_ra;
long pm_dec;
bool tag
char catalog;
};
int n1 = sizeof(s1);
int n2 = sizeof(s2);
结果是: n1 = 28;
n2 = 32;
为什么啊?能不能给我解释一下啊?
struct s1 {
int ra;
int dec;
bool tag;
char catalog;
short rmag;
short bmag;
short jmag;
short hmag;
short kmag;
long pm_ra;
long pm_dec;
};
struct s2 {
int ra;
int dec;
short rmag;
short bmag;
short jmag;
short hmag;
short kmag;
long pm_ra;
long pm_dec;
bool tag
char catalog;
};
int n1 = sizeof(s1);
int n2 = sizeof(s2);
结果是: n1 = 28;
n2 = 32;
为什么啊?能不能给我解释一下啊?