public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "sherpya at netfarm dot it" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/45317] New: struct union misalignment Date: Wed, 18 Aug 2010 03:52:00 -0000 [thread overview] Message-ID: <bug-45317-10752@http.gcc.gnu.org/bugzilla/> (raw) 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
next reply other threads:[~2010-08-18 3:52 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2010-08-18 3:52 sherpya at netfarm dot it [this message] 2010-08-18 8:19 ` [Bug c/45317] " schwab at linux-m68k dot org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-45317-10752@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).