This is the mail archive of the
cygwin@sourceware.cygnus.com
mailing list for the Cygwin project.
I found another compiler bug!
- To: Win32 Mailing List <gnu-win32 at cygnus dot com>
- Subject: I found another compiler bug!
- From: Jonathan Lanier <jonathan at westwood dot com>
- Date: Wed, 7 May 1997 15:16:46 -0700 (PDT)
- cc: colin at bird dot fu dot is dot saga-u dot ac dot jp
Attached is an example of a serious bug in the GCC compiler. The gist of
it is, if you use packed structures in GCC, and then attempt to use
bitfields in those packed structures, the compiler completely
miscalculates the offsets for the data in the structure.
This example demonstrates a C++ class containing only 2 members. Each
one is initialized separately, and the resulting answers printed for each
member should be different, but they are not. Removing the
__attribute__((packed)) keyword gets rid of the error, but it means you
can't pack your structures, which in my case is something I really need
to do!
Does anyone know if this bug was previously known, or if it exists on
other architectures?
- Jonathan
jonathan@westwood.com
#include <stdio.h>
class BadBits
{
public:
BadBits(unsigned dummy);
unsigned BitBrain:1;
unsigned Dummy;
} __attribute__((packed));
BadBits::BadBits(unsigned dummy)
: BitBrain(false), Dummy(dummy)
{
}
int main(void);
int main(void)
{
BadBits MyBadBits(1);
printf("MyBadBits.BitBrain is %d\n", (int)MyBadBits.BitBrain);
printf(" MyBadBits.Dummy is %d\n", (int)MyBadBits.Dummy);
printf("\n Address of MyBadBits: 0x%lx\n", (unsigned long)&MyBadBits);
printf("Address of MyBadBits.Dummy: 0x%lx\n", (unsigned long)&MyBadBits.Dummy);
return(0);
}