From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29491 invoked by alias); 18 Aug 2010 03:52:07 -0000 Received: (qmail 29448 invoked by uid 48); 18 Aug 2010 03:51:54 -0000 Date: Wed, 18 Aug 2010 03:52:00 -0000 Subject: [Bug c/45317] New: struct union misalignment X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "sherpya at netfarm dot it" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2010-08/txt/msg01444.txt.bz2 Hi, bug or feature? I have this sample: #include #include #include #include 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