I have 2 array: the first one is 8 unsigned char, and the second one is 4 unsigned short, for some algorithm compatibility issue i need to use the short array with the values of the char array, to do so i'm doing a loop
j = 0;
for(i=0; i<8; i+=2)
{
short_array[j] = *(unsigned short*) (char_array + i);
j++;
}
Everything work fine here, but in some previous attempt to build this up, i've tried the following (this is obviously not the correct answer)
j = 0;
for(i=0; i<8; i+=2)
{
short_array[j] = (unsigned short*) *(&(char_array + i));
j++;
}
QUESTION:
Assuming the following char_array = {0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88}
When I do the first one short_array = {0x1122, 0x3344, 0x5566, 0x7788}
But when I do the second one, short_array = {0x3344, 0x5566, 0x7788, ???} (where ??? is undefined since it is a value in the memory and may change).
Can you explain why this i happening?
PS: My compiler suite is C251 from Keil