[英]Error with struct option: array type has incomplete element type
I try to build a function for parsing cmd line. 我尝试构建一个解析cmd行的函数。 But, when I define the
long_options
array I get the compile errors: 但是,当我定义
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'
The code: 代码:
//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'}
};
}
}
Can you please help why I get these errors? 你能帮我解释为什么我会收到这些错误吗?
Make sure you do: 确保你这样做:
#include <getopt.h>
in the beginning of the C file, to pull in the getopt()
function prototyp and its related declarations, including struct option
. 在C文件的开头,引入
getopt()
函数原型及其相关的声明,包括struct option
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.