简体   繁体   English

无效的初始值设定项:将值从结构分配给结构数组时

[英]Invalid initializer : While assigning value from struct to a struct array

Suppose I have two structs.假设我有两个结构。 One struct is a simple struct with a set of elements.一个结构是具有一组元素的简单结构。

typedef struct __attribute__ ((packed)) {
        float a1;
        float a2;
        uint32_t b1;
        uint32_t b2;
} item;

Other struct is simply an array of previous struct item .其他 struct 只是前一个 struct item的数组。

typedef struct __attribute__ ((packed)) {
        item item_queue[65000];
} item_arr;

What I need to do is to get an element from item_arr and assign it to an array of item s.我需要做的是从 item_arr 获取一个元素并将其分配给一个item数组。 I'm trying to achieve it in this way.我正试图以这种方式实现它。

item_arr profile_arr[16] = {0};

After assigning values to profile_arr, I assigned an element from item_arr to new item array.在为 profile_arr 赋值后,我将 item_arr 中的一个元素分配给了新的 item 数组。

item temp_q[65000] = profile_arr[0].item_queue;

But This gives me error: invalid initializer .但这给了我错误: invalid initializer

Am I doing the initialization in a wrong way?我是否以错误的方式进行初始化? Any help would be appreciated.任何帮助,将不胜感激。

If you just want to copy profile_arr[0].item_queue to temp_q , you can use 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));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM