attr_p2_05_packed_with_field_aligned.c (531B)
1 /* Phase 2: packed record + field-level aligned. The packed attribute on 2 * the record reduces alignment to 1 for fields without their own align; 3 * a field-level aligned(N) can still raise its own alignment. 4 * Layout: a @ 0 (1 byte), b @ 4 (aligned(4) on a packed record). 5 * Return offsetof(S, b) * 10 + sizeof(S). Phase 2: 4*10 + 8 = 48. */ 6 struct __attribute__((packed)) S { 7 char a; 8 int b __attribute__((aligned(4))); 9 }; 10 11 int test_main(void) { 12 return (int)__builtin_offsetof(struct S, b) * 10 + (int)sizeof(struct S); 13 }