Shark Deng

Interactive Designer @Shanju Design in Shanghai

touched caffe / mxnet / python / wordpress / bootstrap / Arduino / Raspberry Pi / webgl / three.js / PIXI / 3dMax

Email

Github

struct对齐

2019-11-13 00:01:58

#include <stdio.h>
#include <stdlib.h>

//32位的CPU内存以4字节对齐,64位以8字节对齐
//gcc默认4

#pragma pack(8) //没用
typedef struct _parent {
    int data;
} parent; //4

typedef struct _child {
    struct _parent parent; //4
    int data; //4
} child; //8

typedef struct _test {
    double c; //8
    char b; //1
    int a; //4
} test; //16


int main(int argc, char *argv[])
{
    printf("parent %lu, child %lu, test %lu\n", sizeof(parent), sizeof(child), sizeof(test));
}

 



——By SharkDeng
如果你喜欢我的文章,欢迎红包赞赏

Leave a Reply

Your email address will not be published. Required fields are marked *