__attribute__((packed)) behavior with gcc and g++ [gcc version 3.2 20020903]

Milind Changire milindc@telesoftnet.com
Wed Aug 4 15:43:00 GMT 2004


Following peice of code compiles under gcc and reports the size of
struct as 11, as expected.  However g++ just does not like the code
and reports an error 'semicolon missing after enum declaration'
g++ 3.4.1 reports a 'warning: `packed' attribute ignored' and I get
the size of struct as 14.
I'd like to pack structures and cause enums to use mininum possible
space, mostly a single byte, under gcc 3.2.
Arch: i686
------
#include <stdio.h>

#pragma pack(1)
typedef enum {
	Red,
	Green,
	Blue
} __attribute__((packed)) MYENUM;

struct pragma_struct_t {
	char	ch;
	int	val;
	char	ch2;
	long	len;
	MYENUM	color;
};
#pragma pack(0)

int main()
{
	printf("sizeof(struct pragma_struct_t)= %d\n",
	sizeof(struct pragma_struct_t));
	return 0;
}
------

How do I get this to work under g++ 3.2?
Any patches or suggestions?

-Milind




More information about the Gcc-help mailing list