Forum Discussion
Altera_Forum
Honored Contributor
10 years agoIt's generally not a good idea to use C structs when defining data structures with strict layout requirements. You can do it by carefully examining the resulting code, using compiler specific directives and adding pad bytes as needed, but this isn't portable. I like to use# defines for offsets and shift values, then macros to pack/unpack data fields. I use these techniques whenever data is shipped to something that uses a different compiler or CPU architecture, or if a specific layout is defined in a requirement or standards document. That's the only way to be sure that the compiler isn't tampering with how you want it.