3 ms·
If you've got control over the type of the pointee and not just the pointer, __attribute__((packed)) can work for this. struct foo {
by mtklein 3y ago
If you've got control over the type of the pointee and not just the pointer, __attribute__((packed)) can work for this.
struct foo { int x; };
struct bar { __attribute__((packed)) int x; };
_Static_assert(_Alignof(struct foo) == 4, "");
_Static_assert(_Alignof(struct bar) == 1, "");
- loeg 3y agoYeah, I end up using __attribute__((packed)) for this at work. For tortured reasons, part of our codebase allocates memory with only 8-byte alignment, but the buffer is cast to a type that would have 16-byte alignment without __attribute__((packed)). As a result Clang wants to generate VMOVDQAs that require 16-byte alignment, unless you use packed, in which case it generates VMOVDQU.