This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

I found another compiler bug!


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);

}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]