Article View: gnu.g++.bug
Article #10gcc 2.2.2 C++ bug in handling : 0 bit fields
From: Jim Robinson
Date: Thu, 29 Oct 1992 14:18
Date: Thu, 29 Oct 1992 14:18
78 lines
3971 bytes
3971 bytes
There appears to be a bug in gcc's (2.2.2) handling of :0 bit fields when
specifying C++ as the language of choice. When the following program is
compiled for C it does what one would expect and positions structure member
'c' of structure 'foo' at an offset of 4 bytes from the beginning of the
structure. However, when the same program is compiled for C++ 'c' is
positioned at an offset of 8 bytes from the beginning of the structure,
apparently creating an "empty" word. As well, the C++ compilation
apparently rounds up the size of the structure to the nearest word, whereas
the C compilation does not. Note this is on a SPARC running SunOS 4.1.1.
******************* x.c *********************************************
#include <stdio.h>
#include <stddef.h>
struct foo {
char a;
char b;
unsigned int : 0; /* force word alignment */
char c;
};
int
main(int argc, char **argv)
{
struct foo bar;
printf("sizeof(bar) = %d\n", sizeof(bar));
printf("offsetof b = %d; offsetof c = %d\n", offsetof(struct foo, b),
offsetof(struct foo, c));
return(0);
}
******************* C compiled *********************************************
cd /tmp/
make -k x CFLAGS="-v -x c"
gcc -v -x c x.c -o x
Reading specs from /van/pdsw/lib.sun4/gcc-lib/sparc-sun-sunos4.1/2.2.2/specs
gcc version 2.2.2
/van/pdsw/lib.sun4/gcc-lib/sparc-sun-sunos4.1/2.2.2/cpp -lang-c -v -undef -D__GNUC__=2 -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ -D__sparc -D__sun -D__unix x.c /usr/tmp/cca16395.i
GNU CPP version 2.2.2 (sparc)
/van/pdsw/lib.sun4/gcc-lib/sparc-sun-sunos4.1/2.2.2/cc1 /usr/tmp/cca16395.i -quiet -dumpbase x.c -version -o /usr/tmp/cca16395.s
GNU C version 2.2.2 (sparc) compiled by GNU C version 2.2.2.
/van/pdsw/lib.sun4/gcc-lib/sparc-sun-sunos4.1/2.2.2/as -o x.o /usr/tmp/cca16395.s
/van/pdsw/lib.sun4/gcc-lib/sparc-sun-sunos4.1/2.2.2/ld -e start -dc -dp -o x /lib/crt0.o -L/van/pdsw/lib.sun4/gcc-lib/sparc-sun-sunos4.1/2.2.2 -L/van/pdsw/lib.sun4 x.o -lgcc -lc -lgcc
------------- run it ------------
sun33k(2450) /tmp/x
sizeof(bar) = 5
offsetof b = 1; offsetof c = 4
sun33k(2451)
******************* C++ compiled *******************************************
cd /tmp/
make -k x CFLAGS="-v -x c++"
gcc -v -x c++ x.c -o x
Reading specs from /van/pdsw/lib.sun4/gcc-lib/sparc-sun-sunos4.1/2.2.2/specs
gcc version 2.2.2
/van/pdsw/lib.sun4/gcc-lib/sparc-sun-sunos4.1/2.2.2/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ -D__sparc -D__sun -D__unix x.c /usr/tmp/cca16404.i
GNU CPP version 2.2.2 (sparc)
/van/pdsw/lib.sun4/gcc-lib/sparc-sun-sunos4.1/2.2.2/cc1plus /usr/tmp/cca16404.i -quiet -dumpbase x.cc -version -o /usr/tmp/cca16404.s
GNU C++ version 2.2.2 (sparc) compiled by GNU C version 2.2.2.
/van/pdsw/lib.sun4/gcc-lib/sparc-sun-sunos4.1/2.2.2/as -o x.o /usr/tmp/cca16404.s
/van/pdsw/lib.sun4/gcc-lib/sparc-sun-sunos4.1/2.2.2/ld -e start -dc -dp -o x /lib/crt0.o -L/van/pdsw/lib.sun4/gcc-lib/sparc-sun-sunos4.1/2.2.2 -L/van/pdsw/lib.sun4 x.o -lgcc -lc -lgcc
------------ run it -------------
sun33k(2452) /tmp/x
sizeof(bar) = 12
offsetof b = 1; offsetof c = 8
sun33k(2453)
****************************************************************
--
Jim Robinson
robinson@mdd.comm.mot.com
{ubc-cs!van-bc,uunet}!mdivax1!robinson
Technical Details
Message-ID:
<92Oct29.191913est.62@jarvis.csri.toronto.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!ogicse!uwm.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!mdivax1.UUCP!robinsonShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!ogicse!uwm.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!mdivax1.UUCP!robinson From: robinson@mdivax1.UUCP (Jim Robinson) Newsgroups: gnu.g++.bug Subject: gcc 2.2.2 C++ bug in handling : 0 bit fields Message-ID: <92Oct29.191913est.62@jarvis.csri.toronto.edu> Date: 29 Oct 92 14:18:28 GMT Article-I.D.: jarvis.92Oct29.191913est.62 Sender: gnulists@ai.mit.edu Reply-To: robinson@mdd.comm.mot.com (Jim Robinson) Distribution: gnu Organization: Motorola - Mobile Data Division; Richmond, BC Lines: 78 Approved: bug-g++@prep.ai.mit.edu