Hi all,

here is the result on ARM of my little program:

[EMAIL PROTECTED]:/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;
}

Reply via email to