48.结构体位域获取内存模型
生活随笔
收集整理的這篇文章主要介紹了
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 = # 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 }
運行結果:
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 = # 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
總結
以上是生活随笔為你收集整理的48.结构体位域获取内存模型的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 268. Missing Number
- 下一篇: 网络流24题之魔术球问题