现在,我需要一个更复杂的结构,而不是I found a way *作为值,我需要一个结构(名为atom_s)来静态初始化项目数组。
typdef struct atom_s {
const char *val;
const char *filter;
} atom_t;
struct
{
const char *key;
const atom_t **values;
} key_to_values[] =
{
{ .key = "foo", .values = (const atom_t *[]) { NULL } },
{ .key = "bar", .values = (const atom_t *[]) { { .val = "foo", .filter = "bar" }, NULL } },
};问题是:我不知道如何在上面的数组声明中初始化atom_s,也不知道这是否可能。数组的第二行( key = "bar")不能编译:
warning: braces around scalar initializer
warning: (near initialization for '(anonymous)[0]')
error: field name not in record or union initializer发布于 2012-11-02 17:28:10
{
.key = "bar",
.values = (const atom_t *[]) {
(const atom_t []) {
{ .val = "foo", .filter = "bar" }
// how is the user going to know this array has one element?
},
NULL
}
},values指向的数组中的每个元素都指向一个atom_t数组(最后一个元素除外,它是null)。您可能还需要一些方法来终止这些内部数组中的每一个,除非它们的长度始终相同。
https://stackoverflow.com/questions/13192427
复制相似问题