On Tue, Jul 01, 2014 at 05:01:43PM +0200, Markus Teich wrote:
> 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.
> 
> Heyho,
> 
> 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.

Do not assume that.  It is wrong in the general case.

Reply via email to