c - [ N ... M ] 在 C 聚合初始值设定项中是什么意思?

来自 sys.c第 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] .

最佳答案

使用 Designated Initializers 进行初始化

基于范围的初始化是一个 gnu gcc 扩展。

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 };

它不是可移植的。使用 -pedantic 编译告诉你。

它在这里是如何工作的?
预处理器替换 #include <asm/unistd.h>其实际内容(它定义了各种符号常量和类型,并声明了各种函数)在基于范围的构造中,然后进一步用于初始化指针数组。

https://stackoverflow.com/questions/10071304/

相关文章:

linux - 从 ps -ef |grep 关键字获取 pid

python - 将 python 列表拆分为其他 "sublists"即较小的列表

python - 何时在 Python 中使用 %r 而不是 %s?

linux - 如何通过 * 将包括隐藏文件在内的所有文件移动到父目录中

linux - Java 进程列表

python - 如何检查变量是否为具有 python 2 和 3 兼容性的字符串

python - 如何为每个子图添加标题

linux - 如何从脚本编辑/etc/sudoers?

python - 将 javadoc 用于 Python 文档

python - 如何在 Windows 7 的命令提示符中运行 Python 程序?