From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9538 invoked by alias); 20 Oct 2007 01:47:53 -0000 Received: (qmail 9486 invoked by uid 48); 20 Oct 2007 01:47:41 -0000 Date: Sat, 20 Oct 2007 01:47:00 -0000 Subject: [Bug c/33823] New: bitfields on packed struct aligns by a few bits if the types differ X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "alexandre dot nunes at gmail dot com" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2007-10/txt/msg01753.txt.bz2 I have two structs (the unions are there for the sake of testing, it still behaves the same without them): #define ATTRIBUTE_PACKED_STRUCT __attribute__((gcc_struct,packed)) #include #include typedef union ATTRIBUTE_PACKED_STRUCT { struct ATTRIBUTE_PACKED_STRUCT { uint8_t a:1, b:7, c:7; uint16_t d:16; uint8_t e:7; uint8_t f:7; uint16_t g:10; uint16_t h:10; uint16_t i:12; uint8_t j:7; uint8_t k:8; uint16_t l:15; }; unsigned char values[14]; } test_struct; typedef union ATTRIBUTE_PACKED_STRUCT { struct ATTRIBUTE_PACKED_STRUCT { uint32_t a:1, b:7, c:7; uint32_t d:16; uint32_t e:7; uint32_t f:7; uint32_t g:10; uint32_t h:10; uint32_t i:12; uint32_t j:7; uint32_t k:8; uint32_t l:15; }; unsigned char values[14]; } test_struct2; These structs have the same effective size, i.e., removing them from the unions, and having sizeof() applied to them yelds the 14 bytes size, but the members dispostion differs, i.e. the 'e' member is a bit ahead in the first struct (test_struct) than in the second. I didn't expect the type change to force an alignment. It that's standard behaviour, then I would like to propose a documentation request; The ms_struct alignment is described quite well on gcc's page, but gcc's default one isn't. If that's not expected behaviour, then what would be? In case it is, could someone please point me to a documentation source, i.e. an ISO C pointer or whatever reasoning is behind this, if any? Thanks. -- Summary: bitfields on packed struct aligns by a few bits if the types differ Product: gcc Version: 4.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: alexandre dot nunes at gmail dot com GCC build triplet: i486-linux-gnu GCC host triplet: i486-linux-gnu GCC target triplet: i486-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33823