Re: [dev] network protocol packing

From: Markus Teich <>
Date: Tue, 1 Jul 2014 17:01:43 +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.


so if every field in the message is a multiple of 4 bytes long, this should fix
the problem? In this case I would just make op an uint32_t and htonl it before
sending, ntohl after receiving.

Received on Tue Jul 01 2014 - 17:01:43 CEST

This archive was generated by hypermail 2.3.0 : Tue Jul 01 2014 - 17:00:13 CEST