Struct Padding

后端 未结 6 447
忘掉有多难
忘掉有多难 2021-01-23 00:09

I am trying to read chunks of data from a file directly into a struct but the padding is causing too much data to be read and the data to be misaligned.

Do I have to man

6条回答
  •  [愿得一人]
    2021-01-23 00:24

    You can change padding by explicitly asking your compiler to align structs on 1 byte instead of 4 or whatever its default is. Depending on environment, this can be done in many different ways, sometimes file by file ('compilation unit') or even struct by struct (with pragmas and such) or only on the whole project.

提交回复
热议问题