我是靠谱客的博主 奋斗星月,这篇文章主要介绍C语言--__attribute__((packed)),现在分享给大家,希望可以做个参考。

 packed的作用是取消字节对齐

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include<stdio.h> typedef struct { int i; //4 char a; //1 char b; //1 char c; //1 //1 }Test1; typedef struct { int i; //4 char a; //1 char b; //1 char c; //1 }__attribute__((packed))Test2; typedef struct { int i; //4 char a; //1 char b; //1 char c; //1 }__attribute__((__packed__))Test3; int main(int argc, char *argv[]) { printf("Test1 = %d rn",sizeof(Test1)); printf("Test2 = %d rn",sizeof(Test2)); printf("Test3 = %d rn",sizeof(Test3)); return 0; } /**输出结果: Test1 = 8 Test2 = 7 Test3 = 7 */

 

最后

以上就是奋斗星月最近收集整理的关于C语言--__attribute__((packed))的全部内容,更多相关C语言--__attribute__((packed))内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(56)

评论列表共有 0 条评论

立即
投稿
返回
顶部