结构体内存对齐_1
发布日期:2021-05-14 09:05:23 浏览次数:15 分类:精选文章

本文共 1695 字,大约阅读时间需要 5 分钟。

������������������������������������������������������������������������������������������TCP/IP������������������������������������������������������C���������������������#pragma pack���������������������������������������������������������������������

���������������������������������������

#pragma pack(1)
struct gif_hdr {
char signature[3];
char version[3];
int width;
int height;
char colormap;
char bgcolor;
char ratio;
} __attribute__((__packed__));
int main(int argc, char *argv[]) {
// ������������������������������������������������������19������
struct gif_hdr v1 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
struct gif_hdr *dsptr;
dsptr = malloc(sizeof(struct gif_hdr));
printf("Structure data size: %d\n", sizeof(struct gif_hdr));
printf("Offset of signature: %d\n", offsetof(struct gif_hdr, signature));
printf("Offset of version: %d\n", offsetof(struct gif_hdr, version));
printf("Offset of width: %d\n", offsetof(struct gif_hdr, width));
printf("Offset of height: %d\n", offsetof(struct gif_hdr, height));
printf("Offset of colormap: %d\n", offsetof(struct gif_hdr, colormap));
printf("Offset of bgcolor: %d\n", offsetof(struct gif_hdr, bgcolor));
printf("Offset of ratio: %d\n", offsetof(struct gif_hdr, ratio));
return 0;
}

������������#pragma pack(1)���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

���������������������offsetof���������������������������������������������������������������������������������������adelphian���������������������������

上一篇:结构体内存对齐——2
下一篇:结构体内存对齐

发表评论

最新留言

初次前来,多多关照!
[***.217.46.12]2025年04月19日 20时07分04秒