public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: ptrottier@invers.fi To: gcc-gnats@gcc.gnu.org Subject: c/8131: Union of struct of union of struct bit field Date: Thu, 03 Oct 2002 03:26:00 -0000 [thread overview] Message-ID: <20021003102540.25977.qmail@sources.redhat.com> (raw) >Number: 8131 >Category: c >Synopsis: Union of struct of union of struct bit field >Confidential: no >Severity: non-critical >Priority: medium >Responsible: unassigned >State: open >Class: wrong-code >Submitter-Id: net >Arrival-Date: Thu Oct 03 03:26:00 PDT 2002 >Closed-Date: >Last-Modified: >Originator: Philippe Trottier / Invers Oy >Release: gcc version 3.2(i686-linux) & 3.1 Apple 20020420 (prerelease) >Organization: >Environment: powerpc-Apple-macosx (Jag 10.2.1) i686-lfs(4.0rc1)-linux >Description: Bit field struct don't pack bit properly(?) when they are in a Union included in a struct. I might be stupid and not know how to do that too... >How-To-Repeat: #include<stdio.h> typedef union { struct { union { struct { int reserved:16; int R:15; }Tx; struct { int R:15; int PPS:1; int I:15; }Rx; }value; int TxRx:1; }sample; unsigned int Raw; }gumpData; typedef union { struct { union { struct { int reserved:16; int R:15; int TxRx:1; }Tx; struct { int R:15; int PPS:1; int I:15; int TxRx:1; }Rx; }value; }sample; unsigned int Raw; }gumpData2; int main(void) { gumpData data; gumpData2 data2; data2.sample.value.Rx.TxRx=0; data2.sample.value.Rx.I=12; data2.sample.value.Rx.R=11; data2.sample.value.Rx.PPS=0; data.sample.TxRx=0; data.sample.value.Rx.I=12; data.sample.value.Rx.R=11; data.sample.value.Rx.PPS=0; printf("Data %x Size: %d\n",data.Raw,sizeof(data)); printf("Data2 %x Size: %d\n",data2.Raw,sizeof(data2)); return(0); } $ gcc test.c $ ./a.out Data 800c000b Size: 8 Data2 c000b Size: 4 >Fix: Workaround : include the bitfield in both union. >Release-Note: >Audit-Trail: >Unformatted:
next reply other threads:[~2002-10-03 10:26 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2002-10-03 3:26 ptrottier [this message] 2002-10-03 3:50 nathan
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=20021003102540.25977.qmail@sources.redhat.com \ --to=ptrottier@invers.fi \ --cc=gcc-gnats@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).