Force Specific Struct Size in C

前端 未结 2 1391

For various reasons, I have some structs I want to force to be specific sizes (in this case 64 bytes and 512 bytes). Both however, are below the somewhat below the sizes I w

2条回答
  •  無奈伤痛
    2021-01-11 16:48

    I don't think that there's any way to automatize this, at least in gcc which is the compiler I use. You have to pad your structs.

    Be careful about automatic alignment of variables in your struct. For example struct example{ char a; int b; }

    does not take 5 bytes, but 8.

提交回复
热议问题