public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/45317]  New: struct union misalignment
@ 2010-08-18  3:52 sherpya at netfarm dot it
  2010-08-18  8:19 ` [Bug c/45317] " schwab at linux-m68k dot org
  0 siblings, 1 reply; 4+ messages in thread
From: sherpya at netfarm dot it @ 2010-08-18  3:52 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-11-15  0:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-45317-4@http.gcc.gnu.org/bugzilla/>
2012-11-15  0:13 ` [Bug c/45317] struct union misalignment sherpya at netfarm dot it
2012-11-15  0:22 ` sherpya at netfarm dot it
2012-11-15  0:36 ` sherpya at netfarm dot it
2010-08-18  3:52 [Bug c/45317] New: " sherpya at netfarm dot it
2010-08-18  8:19 ` [Bug c/45317] " schwab at linux-m68k dot org

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).