Compiled and executed with both GCC and Clang. I expect that the `sizeof` structs A, B, and C are all exactly 8 bytes (on a 32 bits system). But `struct B` is 12 bytes. I know why it is 12 bytes. What I don't understand is why the anonymous struct in `struct B` is padded to 8 bytes. Surely the compiler can figure out that `struct B` is already aligned to 4 bytes? What's going on here?Code:#include <stdio.h>
struct A {
int i;
char a, b, c;
};
struct B {
struct {
int i;
char a, b, c;
};
char d;
};
struct C {
int i;
char a, b, c, d;
};
int main() {
printf("sizeof(struct A) = %lu\n", sizeof(struct A));
printf("sizeof(struct B) = %lu\n", sizeof(struct B));
printf("sizeof(struct C) = %lu\n", sizeof(struct C));
return 0;
}