This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
__attribute__((packed)) behavior with gcc and g++ [gcc version 3.220020903]
- From: Milind Changire <milindc at telesoftnet dot com>
- To: gcc help <gcc-help at gcc dot gnu dot org>
- Date: Wed, 04 Aug 2004 21:18:35 +0530
- Subject: __attribute__((packed)) behavior with gcc and g++ [gcc version 3.220020903]
- Organization: Telesoft
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