假设我有两个结构。一个结构是包含一组元素的简单结构。
typedef struct __attribute__ ((packed)) { float a1; float a2; uint32_t b1; uint32_t b2; } item;
item .
item
typedef struct __attribute__ ((packed)) { item item_queue[65000]; } item_arr;
我需要做的是从item arr中获取一个元素并将其分配给 s、 我正试图用这种方式来实现它。
item_arr profile_arr[16] = {0};
将值分配给profile_arr后,我将item_arr中的元素分配给新的item数组。
item temp_q[65000] = profile_arr[0].item_queue;
错误:初始值设定项无效 .
如果你只是想复制 profile_arr[0].item_queue temp_q ,您可以使用 memcpy .
profile_arr[0].item_queue
temp_q
memcpy
void * memcpy ( void * destination, const void * source, size_t num ); memcpy(temp_q, profile_arr[0].item_queue, sizeof(temp_q));