【发布时间】:2021-11-15 14:56:30
【问题描述】:
我已经搜索了很多,但还没有找到 c 的任何好的解决方案。我想用动态大小初始化一个数组。到目前为止我看到的解决方案是一个链表,但它似乎不符合我的要求。
目前我测试的代码如下
typedef struct
{
const unsigned char widgetCount;
unsigned char index;
lv_obj_t * radiobtnVIEW[widgetCount];
}AssetVIEW;
然后去初始化widgetCount
AssetVIEW View={4};
我得到的错误是
error: 'widgetCount' undeclared here (not in a function)
这个新手非常感谢您的帮助。
【问题讨论】:
-
您似乎正在寻找的是flexible array member。或普通指针。无论哪种方式,如果没有动态分配(即
malloc和朋友),您都无法解决它。 -
这能回答你的问题吗? What is a flexible array member in a struct?
-
@kaylum 编译器会抛出这个错误错误:'sizeof' 对不完整类型'struct AssetVIEW'的无效应用
-
你什么时候做什么?我们看不到您的代码,因此您需要具体说明。在新问题中提供minimal reproducible example。
-
如果您遇到新错误,请发布新问题。