This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
gcc and attribute __packed__
- From: Nicolas DICHTEL <nicolas dot dichtel at 6wind dot com>
- To: gcc at gnu dot org
- Date: Fri, 10 Feb 2006 16:56:20 +0100
- Subject: gcc and attribute __packed__
- Reply-to: nicolas dot dichtel at 6wind dot com
Hi all,
here is the result on ARM of my little program:
root@lanner128:/usr/admin# ./test2
4 5 6 8
2 3 4 6
Is it normal to add an attribute __packed__ on each union{}
contained in a structure, or is it a bug of my compiler ?
On X86, this kind of structure has always the good size.
Regards,
Nicolas
#include <sys/types.h>
union u {
u_int8_t a[2];
u_int16_t b;
};
union up {
u_int8_t a[2];
u_int16_t b;
} __attribute__((packed));
struct a1 {
union u a;
} __attribute__((packed));
struct a2 {
union u a;
u_int8_t b;
} __attribute__((packed));
struct a3 {
union u a;
u_int16_t b;
} __attribute__((packed));
struct a4 {
union u a;
u_int32_t b;
} __attribute__((packed));
struct b1 {
union up a;
} __attribute__((packed));
struct b2 {
union up a;
u_int8_t b;
} __attribute__((packed));
struct b3 {
union up a;
u_int16_t b;
} __attribute__((packed));
struct b4 {
union up a;
u_int32_t b;
} __attribute__((packed));
int main()
{
printf("%d %d %d %d\n",
sizeof(struct a1),
sizeof(struct a2),
sizeof(struct a3),
sizeof(struct a4));
printf("%d %d %d %d\n",
sizeof(struct b1),
sizeof(struct b2),
sizeof(struct b3),
sizeof(struct b4));
return 0;
}