48.结构体位域获取内存模型

数据在linux和windows上是低字节在地位,高字节在高位,以此方法可以验证
运行结果:
 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 
 4 struct weiyu
 5 {
 6     unsigned char w0 : 1;
 7     unsigned char w1 : 1;
 8     unsigned char w2 : 1;
 9     unsigned char w3 : 1;
10     unsigned char w4 : 1;
11     unsigned char w5 : 1;
12     unsigned char w6 : 1;
13     unsigned char w7 : 1;
14 };
15 
16 void main()
17 {
18     int num = -1;
19     int count = 4;//读几次
20 
21     struct weiyu *wei;
22 
23     wei = &num;
24 
25     for (int i = 0; i < count; i++)
26     {
27         printf("%d%d%d%d%d%d%d%d ", (wei + i)->w0, (wei + i)->w1, (wei + i)->w2, (wei + i)->w3, 
28             (wei + i)->w4, (wei + i)->w5, (wei + i)->w6, (wei + i)->w7);
29     }
30     system("pause");
31 }
原文地址:https://www.cnblogs.com/xiaochi/p/8370892.html