gcc-3.3: I think sizeof(struct xxx) return wrong size

Bug #11279 reported by Debian Bug Importer
6
Affects Status Importance Assigned to Milestone
gcc-3.3 (Debian)
Fix Released
Unknown
gcc-3.3 (Ubuntu)
Invalid
High
Matthias Klose

Bug Description

Automatically imported from Debian bug report #286239 http://bugs.debian.org/286239

Revision history for this message
Debian Bug Importer (debzilla) wrote :

Automatically imported from Debian bug report #286239 http://bugs.debian.org/286239

Revision history for this message
Debian Bug Importer (debzilla) wrote :

Message-Id: <email address hidden>
Date: Sat, 18 Dec 2004 20:00:40 +0200
From: BogDan <email address hidden>
To: Debian Bug Tracking System <email address hidden>
Subject: gcc-3.3: I think sizeof(struct xxx) return wrong size

Package: gcc-3.3
Version: 1:3.3.5-3
Severity: critical
Justification: causes serious data loss

try to compile and run this

//-------------------------------
#include <stdio.h>

int main()
{
struct mesaj_primire
{
        unsigned char xf;
        unsigned char cf;
        unsigned char nw;
        unsigned char nl;
        unsigned int posx;
        unsigned int posy;
        unsigned int state;
        unsigned char nwc;
        unsigned char nlc;
        unsigned char crc;
        unsigned short crc16;
};
printf("%i\n",sizeof(mesaj_primire));
return 0;
}

//---------------------------------
#gcc test.cpp -lstdc++ -o test
#./test
24

24!!!! and I think is 21

I try this on my ppc laptop and my x86 desktop and the result is the same (24)

taipan:/# uname -a;gcc -v
Linux taipan 2.6.8.1 #3 Wed Oct 27 18:29:21 EEST 2004 ppc GNU/Linux
Reading specs from /usr/lib/gcc-lib/powerpc-linux/3.3.5/specs
Configured with: ../src/configure -v --enable-languages=c,c++,java,f77,pascal,objc,ada --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-gxx-include-dir=/usr/include/c++/3.3 --enable-shared --with-system-zlib --enable-nls --without-included-gettext --enable-__cxa_atexit --enable-clocale=gnu --enable-debug --enable-java-gc=boehm --enable-java-awt=xlib --enable-objc-gc --disable-multilib powerpc-linux
Thread model: posix
gcc version 3.3.5 (Debian 1:3.3.5-3)
taipan:/#

root@taipan:/# uname -a;gcc -v
Linux taipan 2.6.4 #1 SMP Sun Sep 19 19:28:30 EEST 2004 i686 GNU/Linux
Reading specs from /usr/lib/gcc-lib/i486-linux/3.3.5/specs
Configured with: ../src/configure -v --enable-languages=c,c++,java,f77,pascal,objc,ada,treelang --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-gxx-include-dir=/usr/include/c++/3.3 --enable-shared --with-system-zlib --enable-nls --without-included-gettext --enable-__cxa_atexit --enable-clocale=gnu --enable-debug --enable-java-gc=boehm --enable-java-awt=xlib --enable-objc-gc i486-linux
Thread model: posix
gcc version 3.3.5 (Debian 1:3.3.5-4)
root@taipan:/#

-- System Information:
Debian Release: 3.1
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: powerpc (ppc)
Kernel: Linux 2.6.8.1
Locale: LANG=ro_RO, LC_CTYPE=ro_RO (charmap=ISO-8859-2)

Versions of packages gcc-3.3 depends on:
ii binutils 2.15-5 The GNU assembler, linker and bina
ii cpp-3.3 1:3.3.5-3 The GNU C preprocessor
ii gcc-3.3-base 1:3.3.5-3 The GNU Compiler Collection (base
ii libc6 2.3.2.ds1-19 GNU C Library: Shared libraries an
ii libgcc1 1:3.4.3-4 GCC support library

-- no debconf information

Revision history for this message
In , Falk Hueffner (falk) wrote : Re: Bug#286239: gcc-3.3: I think sizeof(struct xxx) return wrong size

BogDan <email address hidden>, <email address hidden> schrieb am 18.12.04 19:22:37:
>
> Package: gcc-3.3
> Version: 1:3.3.5-3
> Severity: critical
> Justification: causes serious data loss
>
> try to compile and run this
>
> //-------------------------------
> #include <stdio.h>
>
> int main()
> {
> struct mesaj_primire
> {
> unsigned char xf;
> unsigned char cf;
> unsigned char nw;
> unsigned char nl;
> unsigned int posx;
> unsigned int posy;
> unsigned int state;
> unsigned char nwc;
> unsigned char nlc;
> unsigned char crc;
> unsigned short crc16;
> };
> printf("%i\n",sizeof(mesaj_primire));
> return 0;
> }
>
> //---------------------------------
> #gcc test.cpp -lstdc++ -o test
> #./test
> 24
>
> 24!!!! and I think is 21

24 is correct; there needs to be padding to ensure alignment.

Falk

Revision history for this message
Debian Bug Importer (debzilla) wrote :

Message-Id: <email address hidden>
Date: Sat, 18 Dec 2004 20:21:42 +0100
From: "Falk Hueffner" <email address hidden>
To: <email address hidden>
Subject: Re: Bug#286239: gcc-3.3: I think sizeof(struct xxx) return wrong size

BogDan <email address hidden>, <email address hidden> schrieb am 18.12.04 19:22:37:
>
> Package: gcc-3.3
> Version: 1:3.3.5-3
> Severity: critical
> Justification: causes serious data loss
>
> try to compile and run this
>
> //-------------------------------
> #include <stdio.h>
>
> int main()
> {
> struct mesaj_primire
> {
> unsigned char xf;
> unsigned char cf;
> unsigned char nw;
> unsigned char nl;
> unsigned int posx;
> unsigned int posy;
> unsigned int state;
> unsigned char nwc;
> unsigned char nlc;
> unsigned char crc;
> unsigned short crc16;
> };
> printf("%i\n",sizeof(mesaj_primire));
> return 0;
> }
>
> //---------------------------------
> #gcc test.cpp -lstdc++ -o test
> #./test
> 24
>
> 24!!!! and I think is 21

24 is correct; there needs to be padding to ensure alignment.

Falk

Revision history for this message
Matthias Klose (doko) wrote :

24 is correct; there needs to be padding to ensure alignment.

Changed in gcc-3.3:
status: Unknown → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.