什么是用C这种风格的语法? [英] What is this style of syntax in C?

查看:111
本文介绍了什么是用C这种风格的语法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过 sys.c 线123:

 的void * sys_call_table的[__ NR_syscalls] =
{
    [0 ... __NR_syscalls-1] = sys_ni_syscall,
#包括LT&; ASM / unistd.h中>
};

sys_call_table的是一个通用的指针数组,我可以看到。然而什么是符号:

  [0 ... __NR_syscalls-1]

什么是 ...


编辑:结果
我在这里学会了另一种C招:的#include< ASM / unistd.h中> preprocessed 的并与其内容替换,并且分配到 [0 ... _NR_syscalls-1]


解决方案

这是使用初始化 指定初始化

范围根据初始化一个GNU GCC扩展。


  

要初始化一个范围的元素为相同的值,写 [第一...最后] =值。这是一个GNU扩展。例如,

  INT宽度[] = {[0 ... 9] = 1,[10 ... 99] = 2,[100] = 3};


这是不可移植。与 -pedantic 有这么告诉你编译。

它是如何在这里工作?结果
在preprocessor替换的#include&LT; ASM / unistd.h中&GT; ,其实际内容(的它定义杂项符号常量和类型,并声明辅助功能< /在基于范围构建体,然后将其进一步用于初始化指针数组青霉>)。

From sys.c line 123:

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

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

[0 ... __NR_syscalls-1]

What is the ...?


EDIT:
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.

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.

这篇关于什么是用C这种风格的语法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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