This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Can I do this cast?

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;

Parents Reply Children
No data