我试图构建一个解析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'}
};
}
}你能帮我解释一下为什么我会犯这些错误吗?
发布于 2014-04-30 07:24:00
确保你做到了:
#include <getopt.h>在C文件的开头,要拉入getopt()函数prototyp及其相关声明,包括struct option。
https://stackoverflow.com/questions/23382023
复制相似问题