C and C++ : Partial initialization of automatic structure
Refer to:
http://stackoverflow.com/questions/10828294/c-and-c-partial-initialization-of-automatic-structure
The points,
The linked gcc documentation does not talk of Partial Initialization it just talks of (Complete)Initialization or No Initialization.
What is partial Initialization?
The standards do not define Partial initialization of objects, either there is Complete initialization or No-initialization. Partial Initialization is a non-standard terminology which commonly refers a situation where you provide some initializers but not all i.e: Fewer initializers than the size of the array or the number of structure elements being initialized.
Example:
int array[10]={1,2};//Case 1:Partial Initialization
What is (Complete)Initialization or No Initialization?
Initialization means providing some initial value to the variable being created at the same time when it is being created. ie: in the same code statement.
Example:
int array[10]={0,1,2,3,4,5,6,7,8,9};//Case 2:Complete Initialization
int array[10];//Case 3:No Initialization
Following quoted paragraph describes the behavior for Case 3
.
If you do not initialize a structure variable, the effect depends on whether it is has static storage (see Storage Class Specifiers) or not. If it is, members with integral types are initialized with 0 and pointer members are initialized to NULL; otherwise, the value of the structure's members is indeterminate.
The rules regarding Partial Initialization(Case 1
) are well defined by the standard and these rules do not depend on the storage type of the variable being initialized.
AFAIK, All mainstream compilers have 100% compliance to these rules.
Can someone please tell me what the C and C++ standards say
regarding partial automatic structure and automatic array
initialization?
The C and C++ standards guarantee that even if an integer array is
located on automatic storage and if there are fewer initializers in a
brace-enclosed list then the uninitialized elements must be initialized to 0
.
C99 Standard 6.7.8.21
If there are fewer initializers in a brace-enclosed list than there
are elements or members of an aggregate, or fewer characters in a
string literal used to initialize an array of known size than there are
elements in the array, the remainder of the aggregate shall be
initialized implicitly the same as objects that have static storage
duration.
In C++ the rules are stated with a little difference.
C++03 Standard 8.5.1 Aggregates
Para 7:
If there are fewer initializers in the list than there are members
in the aggregate, then each member not explicitly initialized shall be value-initialized (8.5).
[Example:struct S {int a;char* b;int c;};
S ss ={1,"asdf"};initializes
ss.a
with1
,ss.b
with"asdf"
, andss.c
with the value of an expression of the formint()
, that is,0
. ]
While Value Initialization is defined in,
C++03 8.5 Initializers
Para 5:
To value-initialize an object of type T means:
— if T is a class type (clause 9) with a user-declared constructor
(12.1), then the default constructor for T is called (and the
initialization is ill-formed if T has no accessible
default constructor);
— if T is a non-union class type without a user-declared constructor, then every non-static
data member and base-class component of T is value-initialized;
— if T is an array type, then each element is value-initialized;
— otherwise, the object is zero-initialized
C and C++ : Partial initialization of automatic structure的更多相关文章
- [论文分享]Channel Pruning via Automatic Structure Search
authors: Mingbao Lin, Rongrong Ji, etc. comments: IJCAL2020 cite: [2001.08565v3] Channel Pruning via ...
- cvpr2015papers
@http://www-cs-faculty.stanford.edu/people/karpathy/cvpr2015papers/ CVPR 2015 papers (in nicer forma ...
- Github上的1000多本免费电子书重磅来袭!
Github上的1000多本免费电子书重磅来袭! 以前 StackOverFlow 也给出了一个免费电子书列表,现在在Github上可以看到时刻保持更新的列表了. 瞥一眼下面的书籍分类目录,你就能 ...
- Github 的一个免费编程书籍列表
Index Ada Agda Alef Android APL Arduino ASP.NET MVC Assembly Language Non-X86 AutoHotkey Autotools A ...
- 软件工程卷1 抽象与建模 (Dines Bjorner 著)
I 开篇 1. 绪论 II 离散数学 2. 数 (已看) 3. 集合 4. 笛卡尔 5. 类型 6. 函数 7. λ演算 8. 代数 9. 数理逻辑 III 简单RSL 10. RSL中的原子类型和值 ...
- Python.Module.site
site " This module is automatically imported during initialization. The automatic import can be ...
- 两个基于C++/Qt的开源WEB框架
1.tufao 项目地址: https://github.com/vinipsmaker/tufao 主页: http://vinipsmaker.github.io/tufao/ 介绍: Tufão ...
- STM32 HAL drivers < STM32F7 >
Overview of HAL drivers The HAL drivers were designed to offer a rich set of APIs and to interact ea ...
- JavaScript In OA Framework
原文地址:JavaScript In OA Framework (需FQ) “To be or not to be…… is the question…..!” The famous soliloqu ...
随机推荐
- 利用glassfish4任意文件读取拿权限的一些思路
只要讨论的是linux环境测试发现只针对GlassFish4,且基本上是已root运行的http://www.wooyun.org/bugs/wooyun-2010-0144595 zoomeye d ...
- hibernate--联合主键(了解+,掌握-)
如果一个表有多个主键(= =一般比较少) 8.4. 组件作为联合标识符(Components as composite identifiers) 先定义一个类OrderLineId (实现接口,imp ...
- A*(A星)算法Go lang实现
之前发表一个A*的python实现,连接:点击打开链接 最近正在学习Go语言,基本的语法等东西已经掌握了.但是纸上得来终觉浅,绝知此事要躬行嘛.必要的练手是一定要做的.正好离写python版的A*不那 ...
- byte和hexstring,int,string等的转换类
public class HexConversion { /** * 16进制数的字符串转字节数组(16进制转字节数组) * * @param hexString * 16进制字符串 * @retur ...
- StoreKit framework
关于In-APP Purchase 1. 中文文档 基本流程: http://www.cnblogs.com/wudan7/p/3621763.html 三种购买形式及StoreKit code介绍: ...
- 关于java调用linux shell 的问题
问题的提出: shell脚本要做离线的数据处理任务 java调用脚本,将这种处理任务封装成webservice 特点: shell处理单个时间长 每次要处理文件量大 这里目前只做调用分析: 原来的: ...
- [转]layoutSubviews总结
原文链接找不到了,转的时候别人也是转载的,但并未留下原创链接,就当是笔记了. ios layout机制相关方法 - (CGSize)sizeThatFits:(CGSize)size- (void)s ...
- Unity--截取屏幕任意区域
原地址:http://blog.csdn.net/tanmengwen/article/details/8501612 void Update () { if(Input.GetKeyDown(Key ...
- Java检查型异常和非检查型异常
1.代码 public class ExcepTest { /** * @param args */ public static void main(String[] args) { System.e ...
- 2014ACM-ICPC 西安赛区总结
万万没想到,打铁了.以前一直觉得拿铁咖啡的梗是很好笑的,然后有一天这杯咖啡自己喝下去了,就会发现心里真的被梗住了. 复旦的题其实我是有预料到的,前年的复旦题三题从金区到铜区都有,但是从去年的南京赛区开 ...