Re: [dev] network protocol packing

From: Markus Teich <markus.teich_AT_stusta.mhn.de>
Date: Tue, 1 Jul 2014 13:56:04 +0200

Rob wrote:
> You've got alignment issues here - msg will be aligned to support any
> type (as malloc's interface specifies) so msg+1 will most likely be on
> an odd address, one byte off a highly aligned address. This means if
> your struct contains anything other than chars, you'll have UB. This is
> fine on x86, which allows unaligned access with a performance penalty
> but on something like an ARM machine you'll have issues.
>
> You probably want to memcpy the struct in from an existing one.

Heyho Rop,

thanks for your feedback. What about declaring a struct for each message-type:

struct msg_signed_data {
        unsigned int op;
        struct foo data;
        struct bar signature;
};

This should also solve the alignment issues, or am I mistaken here? It also
reduces the amount of memcpy.

--Markus
Received on Tue Jul 01 2014 - 13:56:04 CEST

This archive was generated by hypermail 2.3.0 : Tue Jul 01 2014 - 14:00:10 CEST