Disable structure padding in C without using pragma

前端 未结 6 662
遥遥无期
遥遥无期 2021-01-11 16:33

How can I disable structure padding in C without using pragma?

6条回答
  •  佛祖请我去吃肉
    2021-01-11 16:43

    We can disable structure padding in c program using any one of the following methods.

    -> use __attribute__((packed)) behind definition of structure. for eg.

    struct node {
        char x;
        short y;
        int z;
    } __attribute__((packed));
    

    -> use -fpack-struct flag while compiling c code. for eg.

    $ gcc -fpack-struct -o tmp tmp.c

    Hope this helps. Thanks.

提交回复
热议问题