Hi. I know that Cortex M0 memory transfers must be aligned.
Knowing that, I'm still not sure if the code below is safe? It compiles and it works, but I'm not sure if I'm just lucky?
unsigned int MCUSerialNumber; unsigned char data[8] = {0}; *((unsigned int *)&data[0]) = MCUSerialNumber;
Is the code above identical in every way to this one?
data[0] = MCUSerialNumber & 0xFF; data[1] = (MCUSerialNumber >> 8) & 0xFF; data[2] = (MCUSerialNumber >> 16) & 0xFF; data[3] = (MCUSerialNumber >> 24) & 0xFF;
So to conclude, the short version of my code is not safe?