3
我嘗試構建一個用於解析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'}
};
}
}
能否請你幫我爲什麼得到這些錯誤?
'struct option'看起來像什麼? –