c/1708: bitfield initializations not skipping anonymous fields
andyj@mc.com
andyj@mc.com
Fri Jan 19 15:26:00 GMT 2001
>Number: 1708
>Category: c
>Synopsis: bitfield initializations not skipping anonymous fields
>Confidential: no
>Severity: critical
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Fri Jan 19 15:26:02 PST 2001
>Closed-Date:
>Last-Modified:
>Originator: Andrew Johnson
>Release: gcc-2.95.2
>Organization:
>Environment:
Solaris 2.5.1
>Description:
Anonymous bit fields are not supposed to receive initial
values, according to the ANSI/ISO C language specification.
The gcc-2.7.2 compiler handles this correctly. gcc-2.95.2
does not.
static struct s{unsigned char c;
int :1,:0,:0,i:5,:0,j:6,:1,k:7;} x
= {0xff,16,17,18};
should initialize the fields c, i, j, and k respectively.
The "j" field is not being initialized properly.
>How-To-Repeat:
Compile and execute this program. It fails for both
Solaris and PowerPC.
---
static void equal(int a, int b, char * c) {
if (a == b)
printf("%s %d == %d\n", c, a, b);
else
printf("%s %d != %d\n", c, a, b);
}
int main() {
static struct s{unsigned char c; int :1,:0,:0,i:5,:0,j:6,:1,k:7;} x
= {0xff,16,17,18};
equal(x.c,0xff,"c=");
equal(x.i,16,"x.i=");
equal(x.j,17,"x.j=");
equal(x.k,18,"x.k=");
}
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-bugs
mailing list