From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13484 invoked by alias); 17 Aug 2006 17:44:26 -0000 Received: (qmail 13405 invoked by uid 48); 17 Aug 2006 17:44:19 -0000 Date: Thu, 17 Aug 2006 17:44:00 -0000 Subject: [Bug c++/28763] New: sizeof macro appears broken when bitfields are in structures X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "mcvick_e at iname dot com" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2006-08/txt/msg01367.txt.bz2 List-Id: I have compiled a sample application that demonstrates my problem (see below for the sample code). Basically when I have two structures, one that contains a bitfield and one that does not, the sizeof macro acts differently between the two structures. These structures are identical as far as content (size allocated), yet sizeof fails for the structure containing the bitfield. Accoding to the standards sizeof should report the total number of bytes within a structure (including pad bytes for alignment). However it appears as though when the bitfield mechanism is used, this fails. Here's a sample code specimen that duplicates the problem... -------------------- sample app ---------------------------- struct foo1 { unsigned int bar1 : 10; unsigned int bar2 : 16; unsigned int bar3 : 6; unsigned short bar4; }; struct foo2 { unsigned int bar1; unsigned short bar2; }; int main(void) { static foo1 fubar1 = { 1, 2, 3, 4 }; static foo2 fubar2 = { 1, 2 }; static int sizeofFubar1 = sizeof(foo1); static int sizeofFubar2 = sizeof(foo2); return 0; } ------------------------ end sample app ----------------------- Compile the application with: c++ -gstabs+ -O2 -mno-bit-align -mcpu=603 -mtune=603 -mstrict-align -nostdlib -fno-use-cxa-atexit -fcheck-new -fno-rtti -fno-exceptions -fsigned-char -c sampleApp.cc -o sampleApp.o if you run objdump -D -C -s -x -z sampleApp.o you will see that: sizeof(foo1) reports 6 sizeof(foo2) reports 8 even though the two structures are identical in size and alignment requirements. We have 6600 occurrances of the sizeof macro in our software, so manually padding or using the __attribute__((aligned(4))) isn't very tempting to overcome this problem. Thanks! -- Summary: sizeof macro appears broken when bitfields are in structures Product: gcc Version: 4.0.1 Status: UNCONFIRMED Severity: major Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: mcvick_e at iname dot com GCC build triplet: powerpc-eabi GCC host triplet: x86_64-redhat-linux GCC target triplet: powerpc-unknown-eabi http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28763