struct初始化
摘自C++ Structure Initialization:
The field identifiers are indeed C initializer syntax.
In C++ just give the values in the correct order without the field names.
Unfortunately this means you need to give them all
(actually you can omit trailing zero-valued fields and the result will be the same).
在C++中初始化struct不需要寫出各field的名字,只需要確保各值的順序與field在struct中的順序一致就行。
在getopt.h
中定義了struct option
:
struct option {
const char *name;
int has_arg;
int *flag;
int val;
};
在TensorRT/samples/common/argsParser.h
中,對struct option
型別的變數進行初始化:
static struct option long_options[] = {{"help", no_argument, 0, 'h'}, {"datadir", required_argument, 0, 'd'},
{"int8", no_argument, 0, 'i'}, {"fp16", no_argument, 0, 'f'}, {"useILoop", no_argument, 0, 'l'},
{"useDLACore", required_argument, 0, 'u'}, {"batch", required_argument, 0, 'b'}, {nullptr, 0, nullptr, 0}};