[N ... M]在C聚合初始化程序中是什么意思? [英] What does [ N ... M ] mean in C aggregate initializers?

查看:108
本文介绍了[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是数组的通用指针,我可以看到.但是,表示法是什么:

sys_call_table is a generic pointer to arrays, I can see that. However what is the notation:

[0 ... __NR_syscalls-1]

什么是...?


我在这里学到了另一个C技巧:#include <asm/unistd.h>将被预处理,并替换为其内容并分配给[0 ... _NR_syscalls-1].


I learned another C trick here: #include <asm/unistd.h> will be preprocessed and replaced with its content and assigned to [0 ... _NR_syscalls-1].

推荐答案

使用 指定的初始化器 .

It is initialization using Designated Initializers.

基于范围的初始化是gnu gcc扩展.

The range based initialization is a gnu gcc extension.

要将一系列元素初始化为相同的值,请写入[first ... last] = value.这是一个GNU扩展.例如

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进行编译时会告诉您.

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

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

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.

这篇关于[N ... M]在C聚合初始化程序中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆