I previously posted a question here about aligned access during pointer casting. As a summary, it's better not to use unaligned access to be fully portable because some architecture may throw an exception, or the performance may get quite slower compared to aligned access.
However, there are cases that I want to use one-byte alignment, e.g., during transferring network data, I don't want adding extra padding inside structure. So usually what's done here is:
#pragma pack (push, 1)
struct tTelegram
{
u8 cmd;
u8 index;
u16 addr1_16;
u16 addr2_16;
u8 length_low;
u8 data[1];
};
#pragma pack (pop)
Then you might already know my question: If I enforce one-byte alignment on my struct, does that mean it cannot be fully portable, because struct members are not aligned? What if I want both no padding and portability?