指定的初始值和省略元素 [英] Designated initializers and omitted elements

查看:126
本文介绍了指定的初始值和省略元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能解释一下关于指定初始化以下行:


  

的初始化列表可以省略在聚合中声明的任何地方的元素,而不是仅在结束



解决方案

试试这个<一个href=\"http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=/com.ibm.xlcpp8a.doc/language/ref/designators.htm\"相对=nofollow>链接。

我们的想法是能够初始化期间指的是复杂的类型状结构的成员。例如。

 的struct {
   诠释A,B;
};诠释主(){
  结构S = {.B = 42,.A = -42};
  返回0;
}

灵活性是从指定值时,是独立顺序获得。记住,这是加入C99标准,不得由不完全支持C99编译器支持(或支持该标准的早期版本)。

Can anybody please explain the following line about the designated initializers:

The initializer list can omit elements that are declared anywhere in the aggregate, rather than only at the end.

解决方案

Try this link.

The idea is to be able to refer to members of a complex type like structure during initialization. E.g.

struct s {
   int a, b;
};

int main() {
  struct s = { .b = 42, .a = -42 };
  return 0;
}

The flexibility is gained from being order independent when specifying values. Remember this was added to the C99 standard and may not be supported by compilers which do not support C99 fully (or support an earlier version of the standard).

这篇关于指定的初始值和省略元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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