在 C 聚合初始化器中[ N... M ]是什么意思?

系统控制线123:

void *sys_call_table[__NR_syscalls] =
{
[0 ... __NR_syscalls-1] = sys_ni_syscall,
#include <asm/unistd.h>
};

sys_call_table是一个指向数组的通用指针,我看得出来。但是它的表示法是什么:

[0 ... __NR_syscalls-1]

什么是 ...


编辑:
我在这里学到了另一个 C 技巧: #include <asm/unistd.h>将是 预处理过的,并用它的内容替换,然后分配给 [0 ... _NR_syscalls-1]

2999 次浏览

It is initialization using Designated Initializers.

The range based initialization is a gnu gcc extension.

To initialize a range of elements to the same value, write [first ... last] = value. This is a GNU extension. For example,

 int widths[] = { [0 ... 9] = 1, [10 ... 99] = 2, [100] = 3 };

It is not portable. Compiling with -pedantic with tell you so.

How does it work here?
The preprocessor replaces #include <asm/unistd.h> with its actual contents(it defines miscellaneous symbolic constants and types, and declares miscellaneous functions) in the range based construct, which are then further used for initializing the array of pointers.