我不确定这是否是你想要的,并且这个解决方案是不完整的,因为它只是作为一个例子。此外,它具有高度的平台可靠性。它适用于我的机器(little_endian)。我在 Windows 下使用 Code:Blocks。
typedef struct {
uint16_t lo_word0;
uint16_t hi_word0;
uint16_t lo_word1;
uint16_t hi_word1;
}struct_t;
int main()
{
uint64_t buff_64[4]={0xaaaabbbbccccdddd,0xbbbbccccddddeeee,0x1111222233334444,0x8888aaaabbbbcccc};
uint16_t buff_16[16];
/*Please note that you may use simply:
memcpy(buff_16,buff_64,32);
however that would result in reverse order
with respect to the code below */
struct_t *ptr = (struct_t *)buff_64;
for(int j=0; j<16; ptr++)
{
buff_16[(j++)%16]=ptr->hi_word1;
buff_16[(j++)%16]=ptr->lo_word1;
buff_16[(j++)%16]=ptr->hi_word0;
buff_16[(j++)%16]=ptr->lo_word0;
}
// The check
for(int j=0;j<16;j++)
printf("%x\n",buff_16[j]);
return 0;
}