EGCS 2.91.66 Bug: sizeof() + struct problem (char == and != int)

Tobias Burnus burnusATgmx.de
Fri Sep 17 17:43:00 GMT 1999


Hi,

Using this very short programm:
---------------------------------------------------------------------------
#include <stdio.h>

struct BeginPage{
  short PageNumber;
  int Flags;
  int BB_x;
};

struct BeginPage2{
  short PageNumber;
  int Flags;
  char BB_x;
};


void main(int argc, char *argv[])
{
  printf("sizeof=%d\n",sizeof(BeginPage));
  printf("sizeof=%d\n",sizeof(BeginPage2));
  printf("%d -- %d -- %d\n",sizeof(char),sizeof(short),sizeof(int));
}
---------------------------------------------------------------------------

I get this output:
---------------------------------------------------------------------------
sizeof=12
sizeof=12
1 -- 2 -- 4
---------------------------------------------------------------------------
whereas I had expected it to be 10 and 7 !!

This is with egcs 2.91.66, which comes with SuSE Linux 6.2
(Installed gcc-2.7.2.3-38.rpm without the binaries, called gccfont.rpm,
since I use egcs-990708-3.rpm)

The System is glibc 2.1 based and runing on a Pentium II.

The commandline was (besides g++ test2.cc):
gcc -v --save-temps test2.cc
---------------------------------------------------------------------------
Reading specs from /usr/lib/gcc-lib/i486-linux/egcs-2.91.66/specs
gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
 /usr/lib/gcc-lib/i486-linux/egcs-2.91.66/cpp -lang-c++ -v -undef -D__GNUC__=2
-D__GNUG__=2 -D__cplusplus -D__GNUC_MINOR__=91 -D__ELF__ -Dunix -Di386
-D__i386__ -Dlinux -D__ELF__ -D__unix__ -D__i386__ -D__i386__ -D__linux__
-D__unix -D__i386 -D__linux -Asystem(posix) -D__EXCEPTIONS -Asystem(unix)
-Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ -D__tune_i486__ test2.cc
test2.ii
GNU CPP version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) (i386
Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/g++
 /usr/lib/g++-include
 /usr/local/include
 /usr/i486-linux/include
 /usr/lib/gcc-lib/i486-linux/egcs-2.91.66/include
 /usr/include
End of search list.
 /usr/lib/gcc-lib/i486-linux/egcs-2.91.66/cc1plus test2.ii -quiet -dumpbase
test2.cc -version -o test2.s
GNU C++ version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) (i486-linux)
compiled by GNU C version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release).
 /usr/i486-linux/bin/as -V -Qy -o test2.o test2.s
GNU assembler version 2.9.1 (i486-linux), using BFD version 2.9.1.0.25
 /usr/lib/gcc-lib/i486-linux/egcs-2.91.66/collect2 -m elf_i386 -dynamic-linker
/lib/ld-linux.so.2 /usr/lib/crt1.o /usr/lib/crti.o
/usr/lib/gcc-lib/i486-linux/egcs-2.91.66/crtbegin.o
-L/usr/lib/gcc-lib/i486-linux/egcs-2.91.66 -L/usr/i486-linux/lib test2.o -lgcc
-warn-common -lc -lgcc /usr/lib/gcc-lib/i486-linux/egcs-2.91.66/crtend.o
/usr/lib/crtn.o
---------------------------------------------------------------------------

Tobias


More information about the Gcc-bugs mailing list