I have a struct, whose relevant part is:
typedef struct {
uint64_t *num;
...
} name;
It would naturally have alignment 8 in most architectures, but for reasons (legacy reasons), I need it to have alignment 4, as I can guarantee the latter alignment, but not the former.
A solution I've found is adding __attribute__((packed,aligned(4))) to the declaration.
I've tested it at godbolt.com and it indeed works and produces the correct number of loads on every architecture they have.
GCC docs make no special mention for this combination and clang docs don't mention these attributes at all.
My question is, how portable (between unix-like environments) and future-proof would this be?
Could next year's GCC/clang break the whole thing?
Should I prefer #pragma pack(4) to it, which looks pretty much equivalent?