__attribute__((packed, aligned(4)))?


Does anyone have a good model for how the "packed" and "aligned"
attributes interact?

For example:

struct Foo __attribute__((packed, aligned(4))) {
    int a;
    char b;
    int c;

struct Foo var;

It seems that alignof(var) == 4, but alignof(var.a) == 1. This is
surprising to me.

Is this just a GCC quirk that we've had to emulate or is there a good
reason for it?



This is what gcc does. It's not worth trying to deviate from gcc here.