public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c/8132: Union of struct of union of struct bit field
@ 2002-10-03  3:36 ptrottier
  0 siblings, 0 replies; 2+ messages in thread
From: ptrottier @ 2002-10-03  3:36 UTC (permalink / raw)
  To: gcc-gnats


>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<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:


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

* Re: c/8132: Union of struct of union of struct bit field
@ 2002-10-03  3:51 nathan
  0 siblings, 0 replies; 2+ messages in thread
From: nathan @ 2002-10-03  3:51 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, nobody, ptrottier

Synopsis: Union of struct of union of struct bit field

State-Changed-From-To: open->closed
State-Changed-By: nathan
State-Changed-When: Thu Oct  3 03:51:11 2002
State-Changed-Why:
    still not a bug

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8132


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

end of thread, other threads:[~2002-10-03 10:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-03  3:36 c/8132: Union of struct of union of struct bit field ptrottier
2002-10-03  3:51 nathan

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