This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Bitlield bug?


Hello,
we moved software from intel to powerPC and have have encountered a problem
with bitordering  in Bitfields 
if we use GNU CC 2.7.2 .

We are writing  Firmware for our hardware so we need to access registers of
peripherie and solved it with bitfields.

Following code behave not like expected on  PowerPC architecture although
bitfields should be of type int !

/* start of c-file */
#include "stdio.h>

struct dwordBitfield{
	/*Byte 0*/
	unsigned int b0 :1;   // LSB
	unsigned int b1 :1;
	unsigned int b2 :1;
	unsigned int b3 :1;
	unsigned int b4 :1;
	unsigned int b5 :1;
	unsigned int b6 :1;
	unsigned int b7 :1;
	/*Byte 1*/
	unsigned int b8 :1 ;
	unsigned int b9 :1 ;
	unsigned int b10:1;
	unsigned int b11:1;
	unsigned int b12:1;
	unsigned int b13:1;
	unsigned int b14:1;
	unsigned int b15:1;
	
	/*Byte 2*/
	unsigned int b16 :1;
	unsigned int b17 :1;
	unsigned int b18 :1;
	unsigned int b19:1;
	unsigned int b20 :1;
	unsigned int b21 :1;
	unsigned int b22 :1;
	unsigned int b23 :1;

	/*Byte 3*/
	unsigned int b24 :1 ;
	unsigned int b25 :1 ;
	unsigned int b26:1;
	unsigned int b27:1;
	unsigned int b28:1;
	unsigned int b29:1;
	unsigned int b30:1;
	unsigned int b31:1;    */MSB*/

};

struct dwordBitfield aBitfield;


int main(int argc, char* argv[])
{
	/* setting bits b0,b1 and b8 */
	aBitfield.b0=1;
	aBitfield.b1=1;
	aBitfield.b8=1;

	/* this should be 0x103 seen as dWord*/
	/*because bitfild is of type int !*/
	int* aPointer=(int*)&aBitfield;

	/*following does not show hex 103 or as bit 00000000 00000000
00000001 00000011 on Power PC  */
	printf("Value in Memory seen as WORD: %x\n",*aPointer);
	return 0;
}



/* end of c-file*/
 
So to my questions :
	Is this a bug? (we think so because a bitfield is of type int !  so
byteordering should not matter here !)
	And is it Solved in new Gnu CC versions ?

Whith kind regards
Philipp Schaefer
SIEMENS
			Postal Address
			Siemens AG, A&D PT 2 D
			D-76187 Karlsruhe

			Office Address:
			Oestliche Rheinbrueckenstrasse 50
			D-76187 Karlsruhe
Dipl.-Ing.                      
Philipp Schäfer		Tel.  +49 (0)721 595-7030
R & D Engineer		Fax  +49 (0)721 595-2326
			mailto:philipp.schaefer@siemens.com



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