I am trying to cast a uint8_t array to uint32_t array. However, when i try to do this, I cant seem to be able to access every consecutive 4 bytes.
Let us say I have a uint8_t array with 8 bytes. I would like to access byte 2 -> 6 as one uint32_t.
These all get the same value
If you want bytes 2..6, you're going to have to combine multiple aligned loads to get what you want.
uint32_t *ptr = ...; uint32_t value = (ptr >> 16) | (ptr << 16);
Technically, this is also the portable way to do things in C in general, but we're all spoiled because you don't have to do the extra work on x86, ARM, Power, or other common architectures.