I’m porting an msvc project, which has several libraries and each library has specific structures member alignment. Using default alignment caused lots of fatal misalign problems and googling told me that I can solve this issue by setting alignment for each struct / class / union manually with the __attribute__ ((aligned (MY_ALIGN))) flag, however there is one thing that bothers me:
Let’s say for simplicity sake that project A uses 1 byte alignment and project B, which actively uses project A’s functionality and includes lots of its headers, has 16 bytes alignment. Would there be a problem with that, or am I thinkg too much and it would just work? I have a bad feeling that when building a library, msvc compiler sets alignment for each structs in all headers (no matter if they are included in a project or are referenced by sources). Is this true? And if it is, please tell me, how should I set the alignment to emulate MSVC’s structure member alignment setting?
I don’t think there should be an issue with that. Just remeber that unaligned access (4 byte minimum I think on most systems) will cost you (although you save space albeit not much in some situations). The structures themselves have the attribute and the compiler will do all the pointer arithmetic so as long as the headers don’t mess with each other’s definitions it should be okay.