From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28422 invoked by alias); 3 Oct 2002 10:36:05 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 28384 invoked by uid 71); 3 Oct 2002 10:36:03 -0000 Resent-Date: 3 Oct 2002 10:36:03 -0000 Resent-Message-ID: <20021003103603.28383.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org Resent-Reply-To: gcc-gnats@gcc.gnu.org, ptrottier@invers.fi Received: (qmail 28042 invoked by uid 61); 3 Oct 2002 10:34:36 -0000 Message-Id: <20021003103436.28041.qmail@sources.redhat.com> Date: Thu, 03 Oct 2002 03:36:00 -0000 From: ptrottier@invers.fi Reply-To: ptrottier@invers.fi To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version: gnatsweb-2.9.3 (1.1.1.1.2.31) Subject: c/8132: Union of struct of union of struct bit field X-SW-Source: 2002-10/txt/msg00095.txt.bz2 List-Id: >Number: 8132 >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:36:01 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 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: