This is the mail archive of the gcc-help@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]

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


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



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