Hi, bug or feature? I have this sample: #include <stdio.h> #include <stdlib.h> #include <stddef.h> #include <stdint.h>
int main(void) { union U { struct { uint32_t l; uint32_t h; } d; uint64_t q; }; struct S { uint32_t one; union U two; uint32_t three; }; printf("sizeof(union) = %u\n", sizeof(union U)); printf("offsets %u, %u, %u\n", offsetof(struct S, one), offsetof(struct S, two), offsetof(struct S, three)); return 0; } I have different results: gcc version 4.4.5 20100816 (prerelease) (Debian 4.4.4-9) (32bit) and gcc version 4.3.5 (Debian 4.3.5-2) sizeof(union) = 8 offsets 0, 4, 12 ---------------- gcc version 4.2.5 20090330 (prerelease) [Sherpya] (32bit latest changeset 4.2.5 on mingw) and gcc version 4.4.3 on mingw32 (built from release tarball) sizeof(union) = 8 offsets 0, 8, 16 --- I've discovered the problem by passing struct between a binary compiled with msvc and my code, looks like the 'correct way' is to pad the first int32 in the struct S with 4 byte to make union 'two' aligned to union size (8) Something changed in gcc behavior that I don't known? Regards -- Summary: struct union misalignment Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: sherpya at netfarm dot it GCC build triplet: i486-linux-gnu GCC host triplet: i486-linux-gnu GCC target triplet: i486-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45317