加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

从未见过C方法初始化Linux内核源代码中发现的结构数组

发布时间:2020-12-16 03:35:08 所属栏目:百科 来源:网络整理
导读:55 typedef struct pidmap {56 atomic_t nr_free;57 void *page;58 } pidmap_t;59 60 static pidmap_t pidmap_array[PIDMAP_ENTRIES] =61 { [ 0 ... PIDMAP_ENTRIES-1 ] = { ATOMIC_INIT(BITS_PER_PAGE),NULL } }; 上面的代码片段显示了我在Linux内核源代码
55 typedef struct pidmap {
56         atomic_t nr_free;
57         void *page;
58 } pidmap_t;
59 
60 static pidmap_t pidmap_array[PIDMAP_ENTRIES] =
61          { [ 0 ... PIDMAP_ENTRIES-1 ] = { ATOMIC_INIT(BITS_PER_PAGE),NULL } };

上面的代码片段显示了我在Linux内核源代码中找到的结构数组的初始化.我之前从未见过这种形式的初始化,我无法自己模拟同样的事情.我到底错过了什么?

Source of the code

解决方法

它是一个名为Designated Initializers的GNU / GCC扩展.您可以在 GCC documentation中找到有关它的更多信息.

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读