Disable structure padding in C without using pragma

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

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

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-11 17:01

    Either you let compiler do padding, or tell it not to do using #pragma, either you just use some bunch of bytes like a char array, and you build all your data by yourself (shifting and adding bytes). This is really inefficient but you'll exactly control the layout of the bytes. I did that sometimes preparing network packets by hand, but in most case it's a bad idea, even if it's standard.

提交回复
热议问题