I've noticed something really strange. say I've got the following structure defined
typedef struct
{
uint32_t a;
uint16_t b;
uint32_t c;
} foo;
This structure is contained in a big buffer I receive from network.
The following code works in x86, but I receive SIGBUS
on ARM.
extern void * buffer;
foo my_foo;
my_foo = (( foo * ) buffer)[0];
replacing the pointer dereferencing with memcpy solved the issue.
Searching about SIGBUS in ARM pointed me to the fact that this is related to memory alignment somwhow.
Can someone explain what's going on ?
struct
as packed or thememcpy()
may work (notSIGBUS
), but it won't function properly. – Aminontohl()
,ntohs()
, protobufs, JSON, XSD, XDR, etc). – Amino