Request to REOPEN bug 6385 was DENIED... creating a new bug...
Error previously reported on bug 6385 (against version 3.0.4.) persists in
version 3.4.4. for more elaborated structs, example:
struct bug_struct {
   short a, b, c, d, e, f, g, h, i, j, k, l;
   char m[8];
   float n, o, p, q, r;
   short s;
   char t[20], u[20];
   char v[8];
};
is evaluated as 104 bytes (should be 102).
Following program returns 1:
--------------------------------------------------------------------------------
struct bug_struct {
   short a, b, c, d, e, f, g, h, i, j, k , l;
   char m[8];
   float n, o, p, q, r;
   short s;
   char t[20], u[20];
   char v[8];
};

bug_struct bug;
long int a, b;

const char *explain1 = "The structure above defined is 102 bytes long.";
const char *explain2 = "'a' receives the size of all individual parts: 102.";
const char *explain3 = "'b' receives the size of the struct: 104.";
const char *explain4 = "Program retuns 1.";

int main(void) {
   a = sizeof(bug.a)+sizeof(bug.b)+sizeof(bug.c)+sizeof(bug.d)+
       sizeof(bug.e)+sizeof(bug.f)+sizeof(bug.g)+sizeof(bug.h)+
       sizeof(bug.i)+sizeof(bug.j)+sizeof(bug.k)+sizeof(bug.l)+
       sizeof(bug.m)+sizeof(bug.n)+sizeof(bug.o)+sizeof(bug.p)+
       sizeof(bug.q)+sizeof(bug.r)+sizeof(bug.s)+sizeof(bug.t)+
       sizeof(bug.u)+sizeof(bug.v);
   b = sizeof(bug);
   if (a == b)
      return 0;
   else
      return 1;
}
--------------------------------------------------------------------------------
 * Diagnostic dumps:
 * -----------------

OUTPUT FROM "g++ -v": 
Reading specs from /usr/lib/gcc/i686-pc-cygwin/3.4.4/specs
Configured with: /gcc/gcc-3.4.4/gcc-3.4.4-1/configure --verbose --prefix=/usr
--exec-prefix=/usr --sysconfdir=/etc --libdir=/usr/lib --libexecdir=/usr/lib
--mandir=/usr/share/man --infodir=/usr/share/info
--enable-languages=c,ada,c++,d,f77,java,objc --enable-nls
--without-included-gettext --enable-version-specific-runtime-libs --without-x
--enable-libgcj --disable-java-awt --with-system-zlib --enable-interpreter
--disable-libgcj-debug --enable-threads=posix --enable-java-gc=boehm
--disable-win32-registry --enable-sjlj-exceptions --enable-hash-synchronization
--enable-libstdcxx-debug : (reconfigured) 
Thread model: posix
gcc version 3.4.4 (cygming special) (gdc 0.12, using dmd 0.125)

OUTPUT FROM "g++ -x c++ -Wall -save-temps bug-sizeof.c++ -o bug-sizeof.exe":
<none>

OUTPUT FROM "uname -a":
CYGWIN_NT-5.1 ME109APC3 1.5.18(0.132/4/2) 2005-07-02 20:30 i686 unknown unknown
Cygwin

OUTPUT FROM "./bug-sizeof.exe; echo $?"
1


-- 
           Summary: sizeof still fails calculating size of an structure
                    (sizeof(struct my_struct))
           Product: gcc
           Version: 3.4.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: chrisnaak at yahoo dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26178

Reply via email to