簡體   English   中英

struct option出錯:數組類型的元素類型不完整

[英]Error with struct option: array type has incomplete element type

我嘗試構建一個解析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()函數原型及其相關的聲明,包括struct option

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM