【发布时间】:2011-10-07 07:24:05
【问题描述】:
我知道 struct 是什么,但还没有见过这样的用法。 谁能更详细地向我解释该代码的作用?
static struct option const long_options[] =
{
{"all", no_argument, NULL, 'a'},
{"kernel-name", no_argument, NULL, 's'},
{"sysname", no_argument, NULL, 's'}, /* Obsolescent. */
{"nodename", no_argument, NULL, 'n'},
{"kernel-release", no_argument, NULL, 'r'},
{"release", no_argument, NULL, 'r'}, /* Obsolescent. */
{"kernel-version", no_argument, NULL, 'v'},
{"machine", no_argument, NULL, 'm'},
{"processor", no_argument, NULL, 'p'},
{"hardware-platform", no_argument, NULL, 'i'},
{"operating-system", no_argument, NULL, 'o'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
{NULL, 0, NULL, 0}
};
【问题讨论】:
-
它是一个结构数组的初始化器。
-
在 C 中,
struct
基本上是类型名称的一部分。所以这是struct option
s 的static
、const
数组([]
),命名为long_options
。
标签: c