Reputation: 1063
I am working on a memory allocator. Each allocated buffer starts on an 8-byte boundary and each is preceded by a header for managing the allocation (the header is immediately before the 8-byte-aligned buffer).
The header looks like:
struct header {
uint32_t hword32;
void *hpointer;
};
Assuming that all members of this structure are packed and that a pointer is 64-bit, this structure has a length of 12 bytes and the alignment of each member is correct (because the end of the structure is 8-byte-aligned).
Accordingly, I would like to tell my compiler two things:
How can I do this with gcc?
It is tempting to use __attribute__((packed))
. However, while this
does the trick for 1., my understanding is that it does not cover 2. (i.e. it
causes the compiler to insert code to handle unaligned accesses, which is not needed here).
Upvotes: 1
Views: 61