我尝试构建一个解析 cmd 行的函数。但是,当我定义long_options
数组时,会出现编译错误:
error: array type has incomplete element type
error: field name not in record or union initializer
error: (near initialization for 'long_options')
// and so on for every defined line in the 'long_options'
编码:
//parse_cmd.c
void parse_cmd(int argc, char *argv[]) {
while (1) {
int input_char;
static struct option long_options[] = {
{.name = "dev-name", .has_arg = 1, .val = 'd'},
{.name = "tcp-port", .has_arg = 1, .val = 't'},
{.name = "ib-port", .has_arg = 1, .val = 'i'},
{.name = "seed", .has_arg = 1, .val = 's'},
{.name = "iters", .has_arg = 1, .val = 'I'},
{.name = "mask", .has_arg = 1, .val = 'm'},
{.name = NULL, .has_arg = 0, .val = '\0'}
};
}
}
你能帮助我为什么会得到这些错误吗?