0

Consider the following code from ttyrpld 2.60 include/rpl_packet.h:

struct rpltime {
    uint64_t tv_sec;
    uint32_t tv_usec;
};

union rpldev_evmagic {
    uint32_t n;
    char m[4];
};

struct rpldsk_packet {
    union rpldev_evmagic evmagic;
    uint32_t size;
    struct rpltime time;
} __attribute__((packed));

That is, rpltime is not packed, rpldsk_packet that includes an rpltime member is packed.

If you take the sizeof struct rpldsk_packet using ppc_85xxDP-gcc (GCC) 4.2.2 from the ELDK distribution, you get 24. Using gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3 you get 20. That is, struct rpltime is also packed on the Ubuntu GCC. According to the GCC documentation, I would expect that the sizeof would be 24 with any GCC, incuding gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3.

Did the behavior of the packed attribute regarding unpacked members change between 4.2.2 and 4.4.3? and if so, when? Or is the documentation out-of-date? What did I miss?

Jonathan Ben-Avraham
  • 4,615
  • 2
  • 34
  • 37

0 Answers0