双指针两个结构体数组编译错误
我定义了这个结构:
typedef struct
{
uint16_t short_addr;
uint64_t ieee_addr;
uint8_t LQI;
uint16_t PANId;
} CAMERA;
并且我声明了它的一个数组,如下所示:
static CAMERA device_list [ MAX_NUMBER_OF_DEVICES ];
所有这些都是在特定模块中定义和声明的。 现在,我想从新结构中的主模块创建一个指向该数组的指针。 但我遇到编译错误,而且我不太确定该怎么做。
typedef struct
{
CAMERA * device_list[ MAX_NUMBER_OF_DEVICES ];
} main_struct;
main_struct MAIN_STRUCT;
但问题是我无法将指针的值分配给它。
MAIN_STRUCT.device_list = device_list;
导致以下编译错误:
Error[Pe137]: expression must be a modifiable lvalue
正确的方法是什么?
I have this Structure defined:
typedef struct
{
uint16_t short_addr;
uint64_t ieee_addr;
uint8_t LQI;
uint16_t PANId;
} CAMERA;
And I declared an array of it, like this:
static CAMERA device_list [ MAX_NUMBER_OF_DEVICES ];
all this is defined and declared in a specific module.
Now, I want to create a pointer to that array from the main module from within a new structure.
but I get compilation errors, and I'm not quite sure how to do that.
typedef struct
{
CAMERA * device_list[ MAX_NUMBER_OF_DEVICES ];
} main_struct;
main_struct MAIN_STRUCT;
But the problem is that I can't assign the value of the pointer to that.
MAIN_STRUCT.device_list = device_list;
Caused the following compilation error:
Error[Pe137]: expression must be a modifiable lvalue
What's the right way to do that ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能分配给数组。您还在
main_struct
中声明了它错误,将其声明为指针就足够了(现在您已将其声明为指针数组。)并且它应该可以工作。
如果您确实希望将其作为数组,则将其声明为数组:
并从另一个数组复制到新数组:
You can not assign to an array. You also declare it wrong in
main_struct
, it's enough to declare it as a pointer (right now you have it declared as as array of pointers.)And it should work.
If you really want it as an array, then declare it as an array:
And copy from the other array to the new array:
尝试:
通过您正在做的事情,您创建了一个指向主结构的指针数组;
马里奥
Try:
With what you are doing you create an array of pointers to main struct;
hth
Mario