Bug in gcc?

Aaron J. Grier aaron at frye.com
Thu Jun 5 21:57:34 UTC 2008

On Thu, Jun 05, 2008 at 06:41:20PM +0300, Leon Pollak wrote:
> Hello, all.
> It seems to me I found a bug in gcc, but as it is rtems-provided cross-gcc, I 
> think it was better to ask here first.
> I have the following code:
> template <class TYPE> class sCmnd2DSPs {
> public:
> 	enum eSources {eDiscr=0, eRS1, eRS2, 
> 		eMB1, eMB2, eEth1, eEth2} __attribute__ ((packed));
> 	struct {
> 		eSources	Source;
> 		uchar		Addr;
> 		eCmndCodesDSPs	Opcode;
> 		TYPE		Params; } __attribute__ ((packed));
> ...............
> };
> Everything works fine, but the field Source in the code above occupies 4 
> bytes, despite the packed request.

you are requesting to pack the struct itself, not the elements inside
it.  to pack the elements inside, use:

struct {
	eSources        Source __attribute__ ((packed));
	uchar           Addr __attribute__ ((packed));
	eCmndCodesDSPs  Opcode __attribute__ ((packed));
	TYPE            Params __attribute__ ((packed)); }

> Now, if I take the enumeration declaration out of the class (put it
> above the class declaration), then the Source field occupies 1 byte as
> required.

what is sizeof(enum) on your platform?  on most platforms I have used,
it defaults to sizeof(int).

  Aaron J. Grier  |   Frye Electronics, Tigard, OR   |  aaron at frye.com

More information about the users mailing list