我正在检查Linux内核代码,并发现以下行。方括号是什么意思?
#define __BPF_FUNC_STR_FN(x) [BPF_FUNC_ ## x] = __stringify(bpf_ ## x)
发件人:https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/kernel/bpf/disasm.c#n18
它是这样使用的:
static const char * const func_id_str[] = {
__BPF_FUNC_MAPPER(__BPF_FUNC_STR_FN)
};
答案 0 :(得分:2)
在c99中,为指定的初始化程序引入了一种语法。方括号语法用于数组初始化。所以这行:
int a[] = { [10] = 4 };
将创建一个数组a
,该数组可以容纳11个int
,并将a[10]
初始化为4,其余成员初始化为0。