|
测试不同平台地址对齐代码
char buf[20];
long *p;
for (int i = 0; i < 20; i++) {
buf = i;
}
for (int i = 0; i < 10; i++) {
p = (long*)((char*)(buf + i));
printf(" %x %x \n",p, *p);
}
X86平台输出,与预期符合
bff84228 03020100
bff84229 04030201
bff8422a 05040302
bff8422b 06050403
bff8422c 07060504
bff8422d 08070605
bff8422e 09080706
bff8422f 0a090807
bff84230 0b0a0908
bff84231 0c0b0a09
arm平台输出,第一列地都正确,地址是对齐的,但里面的值不符合预期,
*p的值不对,"."符号表示这内容是随机值,其余与预期值相同
beaca9ac 03020100 03020100
beaca9ad 00030201 ..030201
beaca9ae 01000302 ....0302
beaca9af 02010003 ......03
beaca9b0 07060504 07060504
beaca9b1 04070605 ..070605
beaca9b2 05040706 ....0706
beaca9b3 06050407 ......07
beaca9b4 0b0a0908 0b0a0908
beaca9b5 080b0a09 ..0b0a09
|
|