How to convert uint16_t[2N] to uint32_t[N] effectively?

arrays, c, embedded

Solution

Like this perhaps:

uint16_t arr16[6];
uint32_t *parr32 = (uint32_t*)(&arr16);

And now you can use `parr32[i]` to refer to elements of the overlayed `arr16` array.

Problem

I've got an array of six `uint16_t` which is actually three `uint32_t`, with the bits in the right order and all. How can I cast the former to the latter as effectively as possible? The number of elements in the array is known at compile-time.

Original source