I have a structure whose relevant part is:
typedef struct { uint64_t *num; ... } name;
Naturally, in most architectural elements there is an alignment of 8, but for reasons (obsolete reasons) I need it to have an alignment of 4, since I can guarantee the last alignment, but not the first.
The solution I found adds __attribute__((packed,aligned(4))) to the declaration.
I tested it on godbolt.com and it really works and produces the right amount of workload for each architecture that they have.
GCC docs do not mention this combination, and clang docs do not mention these attributes at all.
My question is: how portable (between unix-like environments) and the future? Can the next year GCC / clang break it all?
Should I use #pragma pack(4) for it, which looks almost equivalent?
source share