gpt4 book ai didi

c - 结构选项错误 : array type has incomplete element type

转载 作者:行者123 更新时间:2023-12-01 13:17:08 30 4
gpt4 key购买 nike

我尝试构建一个解析 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'}
};
}
}

你能帮助我为什么会得到这些错误吗?

最佳答案

确保你这样做:

#include <getopt.h>

在 C 文件的开头,拉入 getopt()函数原型(prototype)及其相关声明,包括 struct option .

关于c - 结构选项错误 : array type has incomplete element type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23382023/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com