c中字节序问题.docx

c中字节序问题

C语言字节对齐问题详解时间:2014-07-19 00:37:40????? 阅读:2315????? 评论:0????? 收藏:0??????[点我收藏+]标签:算法???class???代码???style???int???html???? ?引言? ? ?考虑下面的结构体定义:1 typedef struct{2 char c1;3 short s; 4 char c2; 5 int i;6 }T_FOO;? ? ?假设这个结构体的成员在内存中是紧凑排列的,且c1的起始地址是0,则s的地址就是1,c2的地址是3,i的地址是4。? ? ?现在,我们编写一个简单的程序:1 int main(void){ 2 T_FOO a; 3 printf(c1 - %d, s - %d, c2 - %d, i - %d\n, 4 (unsigned int)(void*)a.c1 - (unsigned int)(void*)a,5 (unsigned int)(void*)a.s - (unsigned int)(void*)a, 6 (unsigned int)(void*)a.c2 - (unsigned int)(void*)a, 7 (unsi

文档评论(0)

1亿VIP精品文档

相关文档