This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/11885] New: Problem with bitfields in packed structs
- From: "stanrost at lcs dot mit dot edu" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 11 Aug 2003 21:09:54 -0000
- Subject: [Bug c/11885] New: Problem with bitfields in packed structs
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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