C99标准支持结构体按成员名称进行指定初始化。
来源:互联网 发布:淘宝网佛经早晚课读本 编辑:程序博客网 时间:2024/06/05 07:15
今天和同事讨论发现,C99支持对结构体进行指定成员的初始化方式了,前阵子在python上见过,感觉很方便,现在C语言也支持了,需要注意的是,要求编译器支持C99的特性。
下面是C99的原文描述,在6.7.8 Initialization 章节有如下描述:
17 Each brace-enclosed initializer list has an associated current object. When no designations are present, subobjects of the current object are initialized in order according to the type of the current object: array elements in increasing subscript order, structure members in declaration order, and the first named member of a union.127)In contrast, a
designation causes the following initializer to begin initialization of the subobject described by the designator.Initialization then continues forward in order, beginning with the next subobject after that described by the designator.128)
下面是C99给出的举例:
34 EXAMPLE 10 Structure members can be initialized to nonzero values without depending on their order:
div_t answer = { .quot = 2, .rem = -1 };
div_t answer = { .quot = 2, .rem = -1 };
0 0
- C99标准支持结构体按成员名称进行指定初始化。
- C99结构体指定初始化
- C99结构体指定初始化
- C99结构体指定初始化
- C99结构体指定初始化
- C99 结构体指定初始化
- C99结构体指定初始化
- C99结构体指定初始化
- C99结构体指定初始化
- C99结构体指定初始化
- C99结构体指定初始化
- C99 结构体指定初始化
- C99结构体指定初始化-tonywang
- Linux C中结构体初始化(C99标准)
- c99结构体指定初始化,以及 __attribute__ 关键字
- C99 Designated initializers(结构体指定初始化)
- C99 Designated initializers(结构体指定初始化)
- c99结构体指定初始化,以及 __attribute__ 关键字
- APK反编译二次打包工具和方法
- 数组知识点
- STL源码剖析 [容器](十二)[RB_Tree]
- 深入浅出CChart 每日一课——快乐高四第十二课 必也正名,Win32标准控件ChartCtrl之初识
- HttpSession
- C99标准支持结构体按成员名称进行指定初始化。
- .NET程序的性能要领和优化建议
- 自定义Adapter的listview(很重要)
- a different object with the same identifier value was already associated with the session:
- java常用API知识点总结
- 解决maven项目update project更改项目编码的问题
- Android Drawable系列(1):自定义背景以及注意事项
- Codeforces 574B Bear and Three Musketeers
- TestLink基本流程