Struct Padding

后端 未结 6 459
忘掉有多难
忘掉有多难 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:28

    No, you don't have to read each field separately. This is called alignment/packing. See http://en.wikipedia.org/wiki/Data_structure_alignment

    C-style cast is equivalent to reinterpret_cast. In this case you use it correctly. You may use a C++-specific syntax, but it is a lot more typing.

提交回复
热议问题