memory alignment within gcc structs

前端 未结 6 517
情歌与酒
情歌与酒 2020-11-29 05:38

I am porting an application to an ARM platform in C, the application also runs on an x86 processor, and must be backward compatible.

I am now having some issues with

6条回答
  •  伪装坚强ぢ
    2020-11-29 05:58

    What is your true goal?

    If it's to deal with data that's in a file or on the wire in a particular format what you should do is write up some marshaling/serialization routines that move the data between the compiler struct that represents how you want to deal with the data inside the program and a char array that deals with how the data looks on the wire/file.

    Then all that needs to be dealt with carefully and possibly have platform specific code is the marshaling routines. And you can write some nice-n-nasty unit tests to ensure that the marshaled data gets to and from the struct properly no matter what platform you might have to port to today and in the future.

提交回复
热议问题