__attribute__使用,一个可以按照自己的内存对齐方式

该代码时基于linux下的

#include<stdio.h>                                                                                                                           
typedef struct attr {
    char date_1;
    int number;
    char date_2
} attr;
typedef struct bute {
    char data_1;
    int num;
    char data_2;
}__attribute__((packed))bute;
typedef struct trib {
    char table;
    int star;
    char tables;
}__attribute__((aligned(8)))trib;
int main() {
    printf("sizeof(attr)==%d  sizeof(bute)==%d   trib == %d\n",sizeof(attr),sizeof(bute),sizeof(trib));
    return 0;
}

运行截图:

attr是以自动对其的方式进行对其的

bute是按照最小变量的对其方式对其的

trib是按照字节指定的对其方式对其的

发布了25 篇原创文章 · 获赞 9 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_39771637/article/details/100154408