[Bug c/11885] New: Problem with bitfields in packed structs
stanrost at lcs dot mit dot edu
gcc-bugzilla@gcc.gnu.org
Mon Aug 11 21:09:00 GMT 2003
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11885
Summary: Problem with bitfields in packed structs
Product: gcc
Version: 3.3.1
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: stanrost at lcs dot mit dot edu
CC: gcc-bugs at gcc dot gnu dot org
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu avr-unknown-unknown
Hi,
I have been hacking for Berkley Motes using nesC, which produces code later
compiled by AVR-GCC. There is a problem with bitfields within packed
structures, which is also reproducible on the native platform (i686-pc-linux-gnu).
The bug is illustrated by the following simple program:
--------------------------------------------------------------
include <stdio.h>
#include <stdint.h>
typedef struct {
uint8_t flag1:2;
uint8_t flag2:1;
uint8_t flag3:1;
uint8_t flag4;
} __attribute__ ((packed)) MyType;
int main(void) {
MyType a;
MyType *b = &a;
b->flag1 = 0;
b->flag2 = 0;
b->flag3 = 0;
b->flag4 = 0;
b->flag4++;
if (b->flag1)
printf("Set\n");
else
printf("Clear\n");
}
--------------------------------------------------------------
This is clearly an error because flag4 should be allocated its own byte
and not packed into the byte with other variables.
Please look into this, as the current methods of circumvention force me
to pad the structures with "reserved" bitfields.
Respectfully,
Stan Rost
More information about the Gcc-bugs
mailing list